Listeners allow you more control over interactions with the ServletContext
and HttpSession
objects and let you efficiently manage the resources
used by a web module.
Application event listeners are classes that implement one or more of the servlet event listener interfaces. Application events let listener objects be notified when servlet contexts and sessions are initialized and destroyed, as well as when attributes are added or removed from a context or session.
Use Servlet context listeners to manage resources or state held at a virtual machine level for the web module. The IDE helps you create two types of context event listeners:
ServletContextListener
, which notifies you that the
servlet context has just been created and is available to service its first
request, or that the servlet context is about to be shut down.ServletContextAttributesListener
, which notifies you
that attributes on the servlet context have been added, removed, or replaced.Use HTTP session listeners to manage state or resources associated with a series of requests made to a web module from the same client or users. The IDE helps you create two types of session event listeners:
HttpSessionListener
, which notifies you that an HttpSession
has been created, invalidated, or timed out.HttpSessionAttributesListener
, which notifies you that
attributes have been added, removed, or replaced on an HttpSession.Listener classes are declared in the deployment descriptor (web.xml
)
using the listener
element. They are listed by class name in the
order in which they are to be invoked.
The IDE provides a wizard to help you create listener classes. For more information
about listeners, see the Java Servlet Specification available at http://java.sun.com/products/servlet
.
See Also | |
---|---|
Creating a Listener Adding a Listener to the Deployment Descriptor |