Following code in my WebFilter:
private final String sessionExpiredPage = "/exception/sessionexpired.xhtml";
private final String loginPage = "/login.xhtml";
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
try {
final HttpServletRequest req = (HttpServletRequest) request;
final HttpServletResponse res = (HttpServletResponse) response;
final HttpSession session = req.getSession(false);
final String reqURI = req.getRequestURI();
if (isRequireSessionControl(req) && isSessionInvalid(req)) {
res.sendRedirect(req.getContextPath() + sessionExpiredPage);
} else {
if (reqURI.indexOf(sessionExpiredPage) >= 0 || reqURI.indexOf(loginPage) >= 0 || (session != null
&& session.getAttribute("username") != null) || reqURI.contains("javax.faces.resource")) {
chain.doFilter(request, response);
} else {
res.sendRedirect(req.getContextPath() + "/login.xhtml");
}
}
} catch (final Exception e) {
e.printStackTrace();
}
}
The idea behind it is the following: For the first time the user calls the url, he will be redirected to login.xhtml. That works good. After a period of time, which is defined in the in web.xml, the session goes invalid.
The filter recognizes the invalid session an tries to redirect to "sessionExpiredPage". But it won't redirect, the current page will be displayed instead.
So, whats wrong with my code, where do i have the error in my mind?