Java/Servlets/Listener

Материал из Java эксперт
Перейти к: навигация, поиск

Application EventListeners

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 HttpSessionAttributeListener Demo

Servlets ServletContextListener Demo