package com.listener;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
/**
* 上下文属性监听
*/
public class ServletContextAttributeListenerDemo implements
ServletContextAttributeListener {
public void attributeAdded(ServletContextAttributeEvent event) {
// 属性增加时触发
System.out.println("** 增加属性 --> 属性名称:" + event.getName() + ", 属性内容:" + event.getValue());
}
public void attributeRemoved(ServletContextAttributeEvent event) {
// 属性删除时触发
System.out.println("** 删除属性 --> 属性名称:" + event.getName() + ", 属性内容:" + event.getValue());
}
public void attributeReplaced(ServletContextAttributeEvent event) {
// 属性替换时触发
System.out.println("** 增加属性 --> 属性名称:" + event.getName() + ", 属性内容:" + event.getValue());
}
}
web.xml
<listener>
<listener-class>com.listener.ServletContextAttributeListenerDemo</listener-class>
</listener>