上下文监听
package com.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
* 上下文监听
*
*/
public class ServletContextListenerDemo implements ServletContextListener {
public void contextDestroyed(ServletContextEvent event) {
//上下文销毁时出发
System.out.println("** 容器销毁-->" + event.getServletContext().getContextPath());
}
public void contextInitialized(ServletContextEvent event) {
//上下文初始化时出发
System.out.println("** 容器初始化-->" + event.getServletContext().getContextPath());
}
}
web.xml
<listener>
<listener-class>com.listener.ServletContextListenerDemo</listener-class>
</listener>