Event Listening

A servlet can be designated as an event listener. This enables the servlet to be notified when a lifecycle event or a change to request or session attributes has occurred.

There are a number of listener interfaces that you can implement in your servlet. All the listener interfaces extend java.util.EventListener.

Table 12.6 provides a list of the listener interfaces.

Table 12.6. Servlet Event Listener Interfaces
Listener InterfaceNotification
ServletRequestAttributeListenerWhen a request attribute is added, removed, or replaced
ServletRequestListenerWhen the processing of a request is started
HttpSessionAttributeListenerWhen a session attribute is added, removed, or replaced
HttpSessionListenerWhen a session is created, replaced, or ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.