4)HttpSessionAttributeListener:
HttpSessionAttributeListener能监测到有人正在往HttpSession里添加属性。你可以采取相应的措施。
例 2.2.4.1
package com;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public class MyHttpSessionAttributeListener implements HttpSessionAttributeListener {
public void attributeAdded(HttpSessionBindingEvent arg0) {
System.out.println("增加了" + arg0.getName() + " " +
arg0.getValue() );
}
public void attributeRemoved(HttpSessionBindingEvent arg0) {
System.out.println("去除了" + arg0.getName() + " " +
arg0.getValue() );
}
public void attributeReplaced(HttpSessionBindingEvent arg0) {
System.out.println("取代了" + arg0.getName() + " " +
arg0.getValue()+"现在的新值是"+arg0.getSession().getAttribute(arg0.getName()) );
}
}
web.xml加入下面这段话
<listener>
<listener-class>com.MyHttpSessionAttributeListener</listener-class>
</listener>
更多请看:https://blog.csdn.net/qq_44594371/article/details/103188512