我如何处理在某些页面上具有JQuery Ajax方法调用的MVC应用程序的会话到期.问题如下:
我怎么能处理这种行为,哪种是处理它的最佳方法(尽可能多地尝试不修改应用程序代码的这么多部分)?
提前致谢.
PD:告诉我使用$.post()Jquery 可能很有用.
我一直在看这个主题的很多帖子,但无法得到一个适用于我的案例的解决方案.
我正在使用带有JSF 2.0的Java EE 6(部署在JBoss AS 7.1上)
在我的web.xml身上:
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)
当会话自动超时时,我希望将用户重定向到登录页面.
我试过的:
方法1:使用过滤器
我试过以下过滤器:
@WebFilter()
public class TimeOutFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
System.out.println("filter called");
final HttpServletRequest req = (HttpServletRequest) request;
final HttpSession session = req.getSession(false);
if (session != null && !session.isNew()) {
chain.doFilter(request, response);
} else {
System.out.println("Has timed out");
req.getRequestDispatcher("/logon.xthml").forward(request, response);
}
} …Run Code Online (Sandbox Code Playgroud)