ServletContextListener
@WebListener
public class ServletContextListenerDemo implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
ServletContextAttributeListener
@WebListener
public class ServletContextAttributeListenerDemo implements ServletContextAttributeListener {
@Override
public void attributeAdded(ServletContextAttributeEvent servletContextAttributeEvent) {
}
@Override
public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
}
@Override
public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
}
}
说明:servletContext上下文监听器,是整个应用在启动的时候加载的context.一个web application只会有一个context.因此,servletContext是对整个appliction全程有效的。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/187163.html