Struts2获取原始请求URI
我想从 struts2 web 应用程序中的 jsp 页面内部获取当前请求 uri。我可以使用以下命令在操作中执行此操作:
ServletActionContext.getRequest().getRequestURI()
...从技术上讲,我想我可以创建一个仅返回该值的操作属性,但我宁愿不将其写入操作中,有没有办法可以访问使用 ognl 表达式在 jsp 中获得相同的值?
编辑: 经过一番尝试后,我意识到,即使我可以在获取 jsp 页面中的 HttpServletRequest.getRequestURI() 值时获取它,它也会更改为 jsp 的路径而不是原始请求 URI,因此将不是我想要的。
因此,我所做的是编写一个拦截器,在将请求分派到 jsp 文件之前尽早获取值,然后将其保存在值堆栈中,然后我可以在 jsp 中引用它。这可能是唯一的解决方案,但如果有人知道不同的信息,请启发我。
I want to get the current request uri from inside a jsp page in a struts2 webapp. I can do this in an action using the following:
ServletActionContext.getRequest().getRequestURI()
... and I supposed technically I could then create a property of the action that just returns that value but I would rathern not write it into the action, is there a way I can access the same value in a jsp using an ognl expression?
EDIT:
After a bit more playing about I have realised that even if I can get the HttpServletRequest.getRequestURI() value in the jsp page by the time I get it, it will have changed to the path of the jsp not the original request URI so will not be what I want.
So instead what I have done is write an interceptor that grabs the value early on before the request is dispatched to the jsp file and then save it in the value stack which I can then refer to it in the jsp. This may be the only solution but if anyone knows different then do enlighten me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题Tiles2 Struts Switch Locale展示了标签的应用,并展示了如何维护参数url(稍后可能有用)。
This question Tiles2 Struts Switch Locale shows an application of the tag and shows how to maintain the parameters on the url (which might be useful for later).