java类文件:
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class UserOnlineListener implements HttpSessionListener {
static int count = 0;
@Override
public void sessionCreated(HttpSessionEvent arg0) {
System.out.println(this.getClass().toString()
+ "sessionCreated(HttpSessionEvent arg0)");
count ++;
}
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
System.out.println(this.getClass().toString()
+ "sessionDestroyed(HttpSessionEvent arg0)");
if(count>0) count --;
}
}
web.xml配置文件:
cn.cnic.dep.util.UserOnlineListener
30
session 到期以后会自动执行,UserOnlineListener中的sessionDestroyed(HttpSessionEvent arg0)方法