如何获取 JSTL/EL 中的前向信息,即包含点的属性
这个问题显示,转发时,请求中的信息对象被更新以反映新文件。例如,当:
用户请求“/abc”-> servlet被调用>转发到/def.jsp
然后在 def.jsp
中 ${request.requestURI}
将是 /def.jsp
而不是 / abc
.如果想要获取原始请求的 URI(或任何其他信息,如 servlet 路径等):
request.getAttribute("javax.servlet.forward.request_uri");
一切都很好,但是我如何通过 JSTL 访问它。 ${javax.servlet.forward.request_uri}
不起作用。该点被视为运算符,而不是名称的一部分。在其他情况下,可以通过将名称放在方括号中并引用它来解决。但这里没有map对象,${['javax.servlet...']}
不起作用。
那么,怎么样?
(我可以将它放在 servlet 中的“dotless”属性中,但这是一种解决方法)
This question shows that when forwarding, the information in the request object is updated to reflect the new file. So for example, when:
user requests "/abc" -> servlet is invoked > forwards to /def.jsp
Then in def.jsp
${request.requestURI}
will be /def.jsp
rather than /abc
. If one wants to obtain the original requested URI (or any other information, like servlet path, etc):
request.getAttribute("javax.servlet.forward.request_uri");
All fine, but how can I access this via JSTL. ${javax.servlet.forward.request_uri}
doesn't work. The dot is considered an operator, rather than part of the name. In other cases, this is solved by putting the name in square brackets and quoting it. But here there is no map object, and ${['javax.servlet...']}
does not work.
So, how?
(I can put it in a "dotless" attribute in the servlet, but that's a workaround)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我记得,事情是这样的:
As far as I remember, it's something like this: