如何在多个servlet转发后从servlet / jsp获取原始请求url [英] How to get the original request url from a servlet/jsp after multiple servlet forwards

查看:456
本文介绍了如何在多个servlet转发后从servlet / jsp获取原始请求url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用struts / tiles工作巡航预订应用程序,使用多个内部servlet / jsp转发到达正确的jsp进行显示。但是,一旦你到达用于呈现页面的最终jsp,那个jsp中的 $ {pageContext.request.requestURL} 调用将返回这个路径 jsp。

I am working on a cruise booking app using struts/tiles that uses multiple internal servlet/jsp forwards to reach the right jsp for display. But, once you reach the final jsp that is used to render the page, the ${pageContext.request.requestURL} call in that jsp returns the path of this jsp.

例如


  1. 原始请求: / booking / getCruiseDetails

  2. 转发至:/booking/validateCruiseDeteails.jsp

  3. 转发至:/ booking / validateUser。 jsp

  4. 最终转发到: /booking/showCruiseDetails.jsp

  1. Original request: /booking/getCruiseDetails
  2. gets forwarded to: /booking/validateCruiseDeteails.jsp
  3. gets forwarded to: /booking/validateUser.jsp
  4. finally gets forwarded to: /booking/showCruiseDetails.jsp

所以,当我调用 $ {pageContext.request.requestURL} 时,在/booking/showCruiseDetails.jsp中获取/
get /booking/showCruiseDetails.jsp

So, in /booking/showCruiseDetails.jsp when I call ${pageContext.request.requestURL} I get /booking/showCruiseDetails.jsp

如何从通过多个转发到达的jsp获取原始(客户端制作的)请求网址。我确实在stackoverflow上找到了以下帖子,提示解决方案此处这里,但它们没有说明如何找到多个转发发生后的原始请求网址。

How do you get the the original (client made) request url from a jsp that has been reached through multiple forwards. I did find the following posts on stackoverflow that hint at the solution here and here, but they don't address how you would go about finding the original request url after multiple forwards have occurred.

推荐答案

我在这篇文章中找到了一个更好的答案[如何检测Java Servlet中的URL转发到JSP?]

I found a better answer in this post [ How do you detect the URL in a Java Servlet when forwarding to JSP? ]

在目标JSP上使用:

request.getAttribute(javax.servlet.forward.request_uri)

找出原始网址是什么。

它不要求你在转发servlet上采取任何额外步骤

It doesn't require you to take any extra steps on the forwarding servlet

这篇关于如何在多个servlet转发后从servlet / jsp获取原始请求url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆