ServletContextListener使用

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");
    }
}

结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/gy99csdn/article/details/114322197
今日推荐