Filter解決sessionが失効し、ログインページにジャンプします.
1562 ワード
環境:DWR+Struts
設定:
1、濾過.DO要求、web.xmlに加入する.
3、登録ページindex.jspのラベルに登録します.
設定:
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のラベルに登録します.
<script language="JavaScript">
if (window != top)
top.location.href = location.href;
</script>