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.