日期:2014-05-16 浏览次数:20544 次
public class SessionTimeoutFilter implements Filter{ public void destroy() { // TODO Auto-generated method stub } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest)request; HttpServletResponse servletResponse = (HttpServletResponse)response; HttpSession session = servletRequest.getSession(); String url = servletRequest.getRequestURI(); String path = url.substring(url.lastIndexOf("/")); String[] s = path.split("_"); if (url.indexOf(".")==-1 && s.length == 2) { SecurityContext securityContext = (SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT"); if (securityContext == null) { servletResponse.sendRedirect(servletRequest.getContextPath()+"/test_timeout"); }else { chain.doFilter(request, response); } }else { chain.doFilter(request, response); } } public void init(FilterConfig filterConfig) throws ServletException { } }
<filter> <filter-name>strutsForSessionTimeout</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>strutsForSessionTimeout</filter-name> <url-pattern>/test_timeout</url-pattern> </filter-mapping> <filter> <filter-name>SessionTimeoutFilter</filter-name> <filter-class>com.edward.SessionTimeoutFilter</filter-class> </filter> <filter-mapping> <filter-name>SessionTimeoutFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
//session timeout Ext.Ajax.on('requestcomplete', function(conn, response, options, e){ var s = response.responseText; if(s.indexOf("{timeout:",0) != -1){ // window.location.reload(); window.location.href = "login.jsp?timeout=true"; } });