Servlets Application Listener : Listener « Servlets « Java






Servlets Application Listener

import javax.servlet.*;
import javax.servlet.http.*;

public class AppListener extends HttpServlet implements ServletContextListener {

    private ServletContext context = null;

    public void contextInitialized(ServletContextEvent event) {
       context = event.getServletContext();
       context.setAttribute("Counter", new Integer(0));
    }

    public void contextDestroyed(ServletContextEvent event) {
       context = event.getServletContext();
       context.log ((String)context.getAttribute("Counter"));
       context.removeAttribute("Counter");
   }
}



           
       








Servlets-Application-Listener.zip( 91 k)

Related examples in the same category

1.Application EventListeners
2.Servlets HttpSessionAttributeListener Demo
3.Servlets ServletContextListener Demo