servlet context listener
阿新 • • 發佈:2018-05-22
servletContextServletContextListener
@WebListener public class ServletContextListenerDemo implements ServletContextListener{ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { } }
ServletContextAttributeListener
@WebListener public class ServletContextAttributeListenerDemo implements ServletContextAttributeListener { @Override public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) { } @Override public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) { } @Override public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) { } }
說明:servletContext上下文監聽器,是整個應用在啟動的時候加載的context.一個web application只會有一個context.因此,servletContext是對整個appliction全程有效的。
servlet context listener