An Event Listener is a class that implements one or more of the event listener
interfaces included with the Java Servlet API, version 1.3. The interfaces are used for
four different kinds of events that can be monitored by an event listener:
- javax.servlet.ServletContextListener - Used to monitor lifecycle events
of a servlet context.
- javax.serlvet.ServletContextAttributeListener - Used to monitor changes
to the servlet context's attributes.
- javax.servlet.http.HttpSessionListener - Used to monitor the lifecycle
of an HTTP session.
- javax.servlet.http.HttpSessionAttributesListener - Used to monitor changes
to an HTTP session's attributes.
The event listeners are listed in the order that they are invoked. One example of an
event listener is a servlet context listener class that manages a database connection.
When the application starts, the listener class is notified so that it can log on to the
database and store the connection in the servlet context. When the web server is shut
down, or the application is removed from the web server, the listener is notified so that
it can close the database connection.