The Java Servlet 2.3 Specification supports application level events
which 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.
The IDE provides a wizard to help you create listener classes. Use the servlet context listener templates to create listener classes that manage resources or state held at a virtual machine level for the web module:
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 the HTTP session listener templates to create listener classes that manage state or resources associated with a series of requests made to a web module from the same client or users:
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.
To create a listener:
You can also create a listener class from within the Explorer. Right-click
the location where the listener will be stored (typically in WEB-INF/Classes
),
then choose New JSP & Servlet
Listeners and the appropriate
listener template from the contextual menu.
For more information about listeners, see the Java Servlet 2.3 Specification
available at http://java.sun.com/products/servlet
.
See Also | |
---|---|
Setting Listener Properties File Location in a Web Module |