container. Attributes Attributes (Web design rates) on the ServletContext have been
container. Attributes Attributes on the ServletContext have been added, removed, or replaced. ServletContextAttributesListener Table 15-2. HttpSession application events and listener interfaces Event type Description Listener interface Lifecycle An HttpSession object has been created, invalidated, or timed out. HttpSessionListener Attributes Attributes on an HttpSession object have been added, removed, or replaced. HttpSessionAttributesListener 15.2.4 Creating an Event Listener The steps for creating an event listener are similar to those of creating filters. There are three primary steps to perform: 1. Create a Java class that implements the event-listener interface for which you are interested in receiving events. This class must contain a no-argument constructor. 2. Declare the event listener in the web application deployment descriptor using the listener element. 3. Package the event listener class along with the rest of the web application resources. 15.2.4.1 Creating the event listener class As when you create filters, the first step is to create a Java class that implements the appropriate listener interface. As an example, we’ll create a Java class that implements the javax.servlet.ServletContextListener interface and is responsible for initializing the logging service when the web application is started. This class is illustrated in Example 15-3. Example 15-3. ServletContextListener interface import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; /** * An example event listener class that * initializes a logging service. */ public classLoggingListener implements ServletContextListener{ private ServletContext context = null; /** * Called by the container before the first request is * processed. This is a good time to initialize * the logging service.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.