Listener classes for servlet context and session changes
The following methods are defined as part of the javax.servlet.ServletContextListener interface...
- void contextInitialized(ServletContextEvent) - Notification that the web application (.war) is ready to process requests.
Place code in this method to see if the created context is for your web application (.war) and if it is, allocate a database connection and store the connection in the servlet context.
- void contextDestroyed(ServletContextEvent) -Notification that the servlet context is about to shut down.
Place code in this method to see if the created context is for your web application (.war) and if it is, close the database connection stored in the servlet context.
Two new listener interfaces are defined as part of the javax.servlet package:
- ServletContextListener
- ServletContextAttributeListener
One new filter interface is defined as part of the javax.servlet package:
- FilterChain interface - methods: doFilter()
Two new event classes are defined as part of the javax.servlet package...
- ServletContextEvent
- ServletContextAttributeEvent
Three new listener interfaces are defined as part of the javax.servlet.http package...
- HttpSessionListener
- HttpSessionAttributeListener
- HttpSessionActivationListener
One new event class is defined as part of the javax.servlet.http package...
- HttpSessionEvent
See Also
Application lifecycle listeners and events
Example: com.ibm.websphere.DBConnectionListener.java
Webapplications: Resources for learning