从 jsp:include 页面重定向

发布于 2024-08-15 07:52:00 字数 488 浏览 3 评论 0原文

如果会话范围中存储的“角色”与请求参数“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2024-08-22 07:52:00

您无法在 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 the url-pattern covering the parent page.

怪我入戏太深 2024-08-22 07:52:00

JSP 包含不允许发送重定向。你必须使用:

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

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

<jsp:include.directive file="url"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文