(A servlet’s ServletConfig object always holds a reference to the ServletContext for that servlet.)
What's the use of a ServletContextListener?
Execute operations on initialization and/or termination of a web-app and provide globally accessible context attributes.
Which interface has to be implemented and which methods overridden in order to establish a database connection on deployment of a web-app, store the connection as context attribute and close it on undeployment or termination of the web-app?
implement ServletContextListener and override both public void contextInitialized(ServletContextEvent event) and public void contextDestroyed(ServletContextEvent event)