KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > web > SimpleListener


1 package test.web;
2
3 import javax.servlet.*;
4 import javax.servlet.http.*;
5
6 /**
7  * Simple context listener, prints changes to the console.
8  *
9  * <p>A ServletContextListener recieves notifications about changes to the servlet context of the web
10  * application they are part of. NOTE: this is a Servlet 2.3 only feature.</p>
11  *
12  * <p>A HttpSessionListener receives notifications about changes to the list of active sessions in
13  * a web application. NOTE: this is a Servlet 2.3 only feature.</p>
14  *
15  * @web.listener
16  *
17  * @author <a HREF="mailto:youremail@yourdomain.com">youremail@yourdomain.com</a>
18  */

19 public final class SimpleListener implements ServletContextListener, HttpSessionListener {
20     /** Constructs a new SimpleListener. */
21     public SimpleListener() {}
22
23     /** Notification that the web application is ready to process requests. */
24     public void contextInitialized(ServletContextEvent sce) {
25         sce.getServletContext().log("The servlet context has been initialized, the web application is ready to process requests.");
26     }
27
28     /** Notification that the servlet context is about to be shut down. */
29     public void contextDestroyed(ServletContextEvent sce) {
30         sce.getServletContext().log("The servlet context is about to be shut down.");
31     }
32
33     /** Notification that a session was created. */
34     public void sessionCreated(HttpSessionEvent hse) {
35         HttpSession session = hse.getSession();
36         session.getServletContext().log("A session was created, id: " + session.getId());
37     }
38
39     /** Notification that a session was invalidated. */
40     public void sessionDestroyed(HttpSessionEvent hse) {
41         HttpSession session = hse.getSession();
42         session.getServletContext().log("A session was invalidated, id: " + session.getId());
43     }
44 }
Popular Tags