我已在服务器中配置了会话超时,并添加了一个过滤器来处理会话超时。但是,当我尝试将其重定向回登录页面时,它无法正常工作。我在网上搜索但没有得到任何结果。我正在使用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没有回复
答案 0 :(得分:0)
也许这个解决方案适合您的需求:
How to redirect to index page if session time out happened in jsf application
如果您需要对会话超时执行某些操作,您还可以在会话状态bean上创建@Destory注释方法。