ServletContextListener使用
@WebListener
public class MyServletContextListener implements ServletContextListener,
HttpSessionListener, HttpSessionAttributeListener {
// -------------------------------------------------------
// ServletContextListener implementation
// -------------------------------------------------------
@Override
public void contextInitialized(ServletContextEvent sce) {
/* This method is called when the servlet context is
initialized(when the Web application is deployed).
You can initialize servlet context related data here.
*/
System.out.println("context init");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
/* This method is invoked when the Servlet Context
(the Web application) is undeployed or
Application Server shuts down.
*/
System.out.println("context destroy");
}
}
结果: