当前位置: 技术问答>java相关
如何在servlet中截获session timeout
来源: 互联网 发布时间:2015-07-15
本文导语: 我想在tomcat中部署session timeout后激发的事件,作一些处理.应该如可来写.哪位高手又指点一二. | package com.listeners; import javax.servlet.ServletContext; import javax.servlet.http.HttpSessionAttributeListener; import...
我想在tomcat中部署session timeout后激发的事件,作一些处理.应该如可来写.哪位高手又指点一二.
|
package com.listeners;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public final class MySessionListener
implements HttpSessionAttributeListener, HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
System.out.println("HttpSession object has been created");
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("HttpSession object has been removed");
}
public void attributeAdded(HttpSessionBindingEvent event) {
System.out.println("An attribute has been added " +
"to an HttpSession object");
}
public void attributeRemoved(HttpSessionBindingEvent event) {
System.out.println("An attribute has been removed " +
"to an HttpSession object");
}
public void attributeReplaced(HttpSessionBindingEvent event) {
System.out.println("An attribute has been replaced " +
"to an HttpSession object");
}
}
com.listeners.MySessionListener
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public final class MySessionListener
implements HttpSessionAttributeListener, HttpSessionListener {
public void sessionCreated(HttpSessionEvent event) {
System.out.println("HttpSession object has been created");
}
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("HttpSession object has been removed");
}
public void attributeAdded(HttpSessionBindingEvent event) {
System.out.println("An attribute has been added " +
"to an HttpSession object");
}
public void attributeRemoved(HttpSessionBindingEvent event) {
System.out.println("An attribute has been removed " +
"to an HttpSession object");
}
public void attributeReplaced(HttpSessionBindingEvent event) {
System.out.println("An attribute has been replaced " +
"to an HttpSession object");
}
}
com.listeners.MySessionListener