1

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.

Vivek Singh
  • 646
  • 3
  • 10
  • 25
  • actually is possible debug jsp with java code inside, if you put a debug point in the page when inclued does it stop there? if you put some html code like a simple write in the inlcued jsp does it show? – RudiDudi Jan 18 '17 at 09:47
  • Yes the code is executing Hello is printing which means the if condition is triggering but not redirect – Vivek Singh Jan 18 '17 at 09:54
  • The question is answered here : [Include another JSP file](http://stackoverflow.com/questions/9110148/include-another-jsp-file#9110412) – talalUcef Jan 18 '17 at 09:56

1 Answers1

3

you are doing a dynamic include with

 <jsp:include page="....

try this syntax

<%@ include file="/WEB-INF/jsp/SessionValidate.jsp" %>
RudiDudi
  • 455
  • 1
  • 7
  • 18