Web Development with JavaServer Pages

Скачать в pdf «Web Development with JavaServer Pages»


Table 12.5 Methods of the javax.servlet.ServletContextListener interface


Method


Description


contextInitialized(event)


Notifies the listening object that the application has been loaded and initialized.


contextDestroyed(event)


Notifies the listening object that the application has been unloaded.

When a container loads an application that includes listeners implementing the servietcontextListener interface, all such listeners are sent a corresponding javax.servlet.ServletContextEvent instance via their contextInitialized() methods, indicating that the application is now ready to receive requests. The application’s ServletContext instance can be retrieved from this event via its getServ-letContext () method. When the application is unloaded by the container, those listeners are then sent another ServletContextEvent event via their contextDe-stroyed() methods.


As indicated in chapter
6, an application’s ServletContext instance—like its sessions—may also be used to store and retrieve attributes. A second listener has been provided in Servlet 2.3 for monitoring access to such application-level attributes. The methods of this interface, javax.servlet.ServletContextAt-tributeListener, are summarized in table 12.6.


Table 12.6 Methods of the javax.servlet.ServletContextAttributeListener interface


Method


Description


attributeAdded(event)


Notifies the listening object that a value has been assigned to a new application attribute.


attributeReplaced(event)


Notifies the listening object that a new value has been assigned to an existing application attribute.


attributeRemoved(event)


Notifies the listening object that an application attribute has been removed.

As indicated in table 12.6, ServletContextAttributeListener’s methods have the same names as those of the HttpSessionAttributeListener interface, and perform similar roles. The most significant difference between these methods and those of HttpSessionAttributeListener is the class of the event object serving as the methods’ parameter. Where the HttpSessionAttributeListener methods are passed HttpSessionBindingEvent objects, the ServletContextAttributeListener’s methods are passed instances of the ServletContextAttributeEvent class.

Скачать в pdf «Web Development with JavaServer Pages»