1. 在web.xml 添加
<listener>
<listener-class>listener.TestListener</listener-class>
</listener>
2. 在包listener包下编辑 TestListener.java, 实现 (implements)抽象接口 ServletContextListener 的两个方法 contextInitialized, contextDestroyed
@Override
public void contextInitialized(ServletContextEvent event) {
logger.info("init.............");
System.out.println(event.getServletContext());
}
@Override
public void contextDestroyed(ServletContextEvent event) {
logger.info("end destroy.............");
System.out.println(event.getServletContext());
}