I have a folder in my project and some jsp file into that folder and I want to check valid session on each page. So I have created a JSP file that contains the session checking code, inside web-inf folder and including that file into other jsp file but the code is executing but response.sendRedirect() not working.
So I have Admin folder that contain all files, WEB-INF/jsp/SessionValidate.jsp file(this file has to be included into admin folder's file. See the comments in the code
Admin/xyz.jsp
<jsp:include page="/WEB-INF/jsp/SessionValidate.jsp"></jsp:include>
WEB-INF/jsp/SessionValidate.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
if(session.getAttribute("Roles")==null){
response.sendRedirect("/Shopping/Login");
<!-- response.sendRedirect(..) -->
System.out.println("hello2");
<!-- Hello is printing -->
}
else{
if(!session.getAttribute("Roles").equals("ADM")){
response.sendRedirect("/Shopping/User");
}
else{%>
<jsp:include page="/WEB-INF/jsp/admin.jsp"></jsp:include>
<%}
}%>
So when I paste this code directly into the xyz.jsp its working but not like this.