session监听
package com.listener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
/**
* 对session的监听
*/
public class HttpSessionListenerDemo implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
// 创建session时触发
System.out.println("** SESSION 创建,SESSION ID = " + event.getSession().getId());
}
public void sessionDestroyed(HttpSessionEvent event) {
// 销毁session时触发
System.out.println("** SESSION 销毁,SESSION ID = " + event.getSession().getId());
}
}
web.xml
<listener>
<listener-class>com.listener.HttpSessionListenerDemo</listener-class>
</listener>