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 is ready to process requests. Place code in this method to see if the created context is for your Web application 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 and if it is, close the database connection stored in the servlet context.

The following methods are defined as part of the javax.servlet.ServletRequestListener interface:

  • public void requestInitialized(ServletRequestEvent re)

    • Notification that the request is about to come into scope

      A request is defined as coming into scope when it is about to enter the first filter in the filter chain that processes the request.

  • public void requestDestroyed(ServletRequestEvent re)

    • Notification that the request is about to go out of scope

      A request is defined as going out of scope when it exits the last filter in its filter chain.

The following listener interfaces are defined as part of the javax.servlet package:

  • ServletContextListener

  • ServletContextAttributeListener

The following filter interface is defined as part of the javax.servlet package:

  • FilterChain interface - methods: doFilter()

The following event classes are defined as part of the javax.servlet package:

  • ServletContextEvent

  • ServletContextAttributeEvent

The following interfaces are defined as part of the javax.servlet.http package:

The following event class is defined as part of the javax.servlet.http package:


 

See Also


Application life cycle listeners and events

 

See Also


Example: com.ibm.websphere.DBConnectionListener.java
Web applications: Resources for learning