我已经在服务器中配置了会话超时,并添加了一个过滤器来处理会话超时。但当我试图将其重定向回登录页面时,它不起作用。我搜索了一下网,但没有找到任何可靠的东西。我正在使用jsf。。我的代码
public class SessionTimeoutFilter implements Filter {
private String timeoutPage = "login.seam";
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request,
ServletResponse response, FilterChain filterChain) throws IOException,ServletException {
if ((request instanceof HttpServletRequest)
&& (response instanceof HttpServletResponse))
{
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
if (isSessionControlRequiredForThisResource(httpServletRequest)) {
if (isSessionInvalid(httpServletRequest))
{
String timeoutUrl = httpServletRequest.getContextPath()
+ "/" + getTimeoutPage();
System.out.println("Session is invalid! redirecting to timeoutpage : " + timeoutUrl);
httpServletResponse.sendRedirect(timeoutUrl);
return;
}
}
}
filterChain.doFilter(request, response);
}
有人能告诉我我做错了什么吗。。。为什么sendredirect没有响应
也许这个解决方案适合您的需求:
如果在jsf应用程序中发生会话超时,如何重定向到索引页
如果您需要对会话超时执行一些操作,还可以在会话statefullbean上创建@Destory注释方法。