I stuck up with doFilter of HttpServletRequest.
Im trying to replace new URL for that request.
My code is as follows:
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) req;
HttpServletResponse httpRes = (HttpServletResponse) res;
//If request resources ==> Continue
if(httpReq.getContextPath().startsWith(httpReq.getContextPath()+"/resources")){
chain.doFilter(req, res);
return;
}
HttpSession session = httpReq.getSession();
EmployeeDTO currentEmployee =(EmployeeDTO)session.getAttribute("currentEmployee");
//If dont have session ==> Return login page
if(currentEmployee == null){
String requestURI = "";
requestURI = httpReq.getRequestURI().replace(httpReq.getRequestURI(), httpReq.getContextPath()+ "/login");
System.out.println(requestURI);
//httpRes.reset();
//httpRes.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
//httpRes.setHeader("Location", requestURI);
httpRes.sendRedirect(requestURI);
chain.doFilter(req, res);
return;
}
chain.doFilter(req, res);
return;
}
But the code above is still not working. How can i do for this?
Thanks in advance!