session监听,需要实现HttpSessionAttributeListener接口
attributeAdded:监听添加session
attributeRemoved:监听删除session
attributeReplaced:监听修改session
package com.gxy.Listener; import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent; public class sessionAttributeListener implements HttpSessionAttributeListener { public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {
// TODO Auto-generated method stub
System.out.println("添加的属性名:"+httpSessionBindingEvent.getName()+",添加的属性值"+httpSessionBindingEvent.getValue());
} public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {
// TODO Auto-generated method stub
System.out.println("删除的属性名:"+httpSessionBindingEvent.getName()+",删除的属性值"+httpSessionBindingEvent.getValue());
} public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {
// TODO Auto-generated method stub
System.out.println("修改的属性名:"+httpSessionBindingEvent.getName()+",修改的属性值"+httpSessionBindingEvent.getValue());
} }
配置web.xml
<listener>
<listener-class>com.gxy.Listener.sessionAttributeListener</listener-class>
</listener>