环境:DWR+ Struts
配置:
1、过滤.DO请求,在web.xml中加入
<web-app> <filter> <filter-name>session-timeout</filter-name> <filter-class>com.manage.common.SessionFilter</filter-class> </filter> <filter-mapping> <filter-name>session-timeout</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
2、写过滤器Filter类
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest requestHttp = (HttpServletRequest) request;
String requestURI = requestHttp.getRequestURI().toLowerCase();
// 判断是否是首次登陆
boolean isLogin = requestURI.indexOf("login") >= 0;
Tsysuser tsysuser = (Tsysuser) requestHttp.getSession().getAttribute("tsysuser");
if (!isLogin && tsysuser == null) {
request.setAttribute("message", "登陆超时,请重新登陆!");
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/index.jsp");
requestDispatcher.forward(request, response);
}else{
chain.doFilter(request, response);
}
}
3、在登陆页面index.jsp的<head></head>标签中加入
<script language="JavaScript"> if (window != top) top.location.href = location.href; </script>