Question

I want the user to be redirected to Login.jsp if the "role" stored in Session Scope doesn't match with the Request Parameter "accessRole"

HomePage.jsp

<jsp:include page="Header.jsp">
<jsp:param value="d" name="accessRole" />
</jsp:include>

Header.jsp

<c:if test="${sessionScope.role!=param.accessRole}">
<c:redirect url="Login.jsp"/> 
</c:if>

The above code does not perform the redirection as expected.

I tried using ExternalContext's redirect() and jsp:forward in place of <c:redirect>, but nothing works.

Was it helpful?

Solution

You cannot redirect inside a JSP include, it's often already too late. If you have read the appserver logs, you should have seen an IllegalStateException: response already committed (just because the content of the parent page is already been sent to the response).

The real solution for this is to implement a Filter which is mapped on the url-pattern covering the parent page.

OTHER TIPS

JSP includes are not allowed to send a redirect. You'll have to use:

<jsp:include.directive file="url"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top