This section explains the event listener functionality of an application.
Event listener functionality is present in each Web application. The application event listener is instantiated when a Web application is deployed. The instantiated application event listener receives the state change event of either one or both of the servlet context object and the session object. The events received by the listener object are as follows:
- Generating a new session object
- Before serializing a session object#1
- After de-serializing a session object#1
- Deleting a session object
- Adding, deleting, and changing attributes of a session object
- Generating a servlet context object
- Deleting a servlet context object
- Adding, deleting, and changing attributes of a servlet context object
- Arrival of requests in a Web application#2
- Completion of request processing in a Web application#2
- Adding, deleting, and changing attributes of a request object#2
- #1
- Servlet API assumes that due to the vendor-specific processing of a session object, a session object is saved and communicated after serializing, and processing is restarted after de-serializing a session object at another point of time.
- The intention of providing such event notifications in session object is to add not just data, but also resources, such as database connections and object references in a session object. In an application designed to add resources to a session object, the resources must be released once before serializing, and then acquired again after de-serializing.
- A configuration in which the resources are added to the session object, if not used with utmost care, the amount of resources required in the entire server will increase immensely, and there might be a shortage of resources. Therefore, use the event listener functionality if you can secure the resources.
- #2
- Can only be used in Web applications compliant with Servlet 2.4 or later specifications.
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.