我有一个 javax.servlet.Filter,如果 HttpSession 是新的,我想在其中重定向到登录页面,如果 HttpSession 过期,我想重定向到注销页面,如果存在 HttpSession,我想重定向到其他页面。
The login and logout pages are external pages. My sample method is given below
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
if (request.getSession(false) == null) {
response.sendRedirect("login page");
} else if (request.getRequestedSessionId() != null && !request.isRequestedSessionIdValid()) {
response.sendRedirect("logout page");
} else {
chain.doFilter(request, response);
}
}
问题是会话过期后,注销页面不呈现。如何让它工作?