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"); } }
1. | Application EventListeners | ![]() | |
2. | Servlets HttpSessionAttributeListener Demo | ![]() | |
3. | Servlets ServletContextListener Demo | ![]() |