ServletContextListener 接口定义了 ServletContext 对象生命周期的 监听行为。 void contextInitialized(ServletContextEvent sce) ServletContext对象创建之后会触发该监听方法,并将ServletContext 对象传递到该方法中。
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("ServletContextLifecycleListener contextInitialized");
}
void contextDestroyed(ServletContextEvent sce)
ServletContext
对象在销毁之前会触发该监听方法,并将
ServletContext
对象传递到该方法中
@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("ServletContextLifecycleListener contextDestroyed");
}
新建listener文件夹中的ServletContextLifecycleListener类
package com.syh.listener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletContextLifecycleListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("ServletContextLifecycleListener contextInitialized");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("ServletContextLifecycleListener contextDestroyed");
}
}
标签:生命周期,监听器,ServletContextLifecycleListener,sce,void,contextDestroyed,ServletContex
From: https://blog.csdn.net/xia_o_s_on/article/details/143685959