package com.itheima.listener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
/*servletContext对象的创建和销毁的监听*/
@WebListener
public class ServletContextListenerDemo implements ServletContextListener {
/*servletContext对象创建时执行此方法*/
public void contextInitialized(ServletContextEvent sce) {
System.out.println("监听到了对象的创建。。。。");
//获取对象
ServletContext servletContext = sce.getServletContext();
System.out.println(servletContext);
}
/*servletContext对象销毁时执行此方法*/
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("监听到了对象的销毁。。。");
}
}
listener-servletContextListener监听器的使用
最新推荐文章于 2023-12-26 19:25:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)