开发者

Redirection from jsp:include page

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 js开发者_开发技巧p:forward in place of <c:redirect>, but nothing works.


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.


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

<jsp:include.directive file="url"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜