目标:用户登录一段时间(如30分钟)没有使用该系统,再操作时系统提示“时间过时,请重新登录”,然后系统自动返回到登录页面。
处理方式:使用Session监听器
WEB.XML文件:
<web-app>
<session-config> 
<session-timeout>30</session-timeout>
</session-config>
<listener>
<listener-class>com.jxc.SessionListen</listener-class>
</listener>
监听器类SessionListen
package com.jxc;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListen implements HttpSessionListener{
   public void sessionCreated(HttpSessionEvent event){
   }
   public void sessionDestroyed(HttpSessionEvent event){
HttpServletRequest request=null;
HttpServletResponse response = null;
try {
event.getSession().getServletContext().getRequestDispatcher("/login.jsp").forward(request,response);
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (ServletException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
结果不行,请问是哪出问题了?