I'm trying to redirect from a servlet controller to a JSP page but it's not working. The scenario is if a user sends a request to the JSP page then at first JSP will invoke the code from servlet. The servlet will then check if the user's session is new or not. If not the servlet will redirect the user to Login page.
To implement this scenario. I've added an JSP:include standard tag in the JSP page.
code from jsp page -
<jsp:include page="/Check_Cookie"/>
And this is the code from the Check_Cookie servlet
HttpSession session = request.getSession();
Cookie[] cookies = request.getCookies();
boolean check = true;
if(session.isNew()){
check = false;
}
if(cookies==null){
check = false;
}
if(!check){
System.out.println("Guest User");
response.sendRedirect("Login.jsp");
return;
}
It seems the code is ok. But the controller is not redirecting to the login page although the user is not logged in.
It would be great if someone help me on this.