从 jsp:include 页面重定向
如果会话范围中存储的“角色”与请求参数“accessRole”不匹配,我希望将用户重定向到 Login.jsp
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>
上面的代码未按预期执行重定向。
我尝试使用ExternalContext 的redirect() 和jsp:forward 代替
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在 JSP include 内部进行重定向,这通常已经太晚了。如果您已阅读应用程序服务器日志,您应该已经看到
IllegalStateException:响应已提交
(只是因为父页面的内容已发送到响应)。真正的解决方案是实现一个
Filter
,它映射到覆盖父页面的url-pattern
上。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 theurl-pattern
covering the parent page.JSP 包含不允许发送重定向。你必须使用:
JSP includes are not allowed to send a redirect. You'll have to use: