I\'m trying to find a method to redirect my request from a filter to the login page but I don\'t know how to redirect from servlet. I\'ve searched but what I find is s
In Filter the response is of ServletResponse
rather than HttpServletResponse
. Hence do the cast to HttpServletResponse
.
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendRedirect("/login.jsp");
If using a context path:
httpResponse.sendRedirect(req.getContextPath() + "/login.jsp");
Also don't forget to call return;
at the end.