Listeners and events for Web applications are another new feature introduced in the Servlet API 2.3 specification. The event-listener model was introduced from JDK 1.1 in the AWT package. You can define a listener for any AWT UI (user interface) element. Any actions or events occurring on the UI element are processed by the AWT listener. The same event-listener model has been incorporated in the servlet specification. Now you can define listeners for two kinds of events:
Depending on the event to be listened to, the listener class has to override the appropriate interface and implement the methods required. Now look in detail at the two main events. ServletContext EventsFive events of the ServletContext can have listeners:
HttpSession EventsThe HttpSession events are described here. Five events of the HttpSession event can have listeners:
|