1.首先写好要添加的监听器 他需要实现ServletContextListener接口里面两个方法
public void contextInitialized(ServletContextEvent sce) {//初始化执行 用于初始数据
System.out.println("--------------------->");
}
public void contextDestroyed(ServletContextEvent sce) {//销毁是执行 用于清理数据
}
2.在web的xml中配置
3.重启服务器就会打印
------------------>