前端动态获取servlet虚拟路径,如何在多个servlet转发后从servlet / jsp获取原始请求url...

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.

For example

Original request: /booking/getCruiseDetails

gets forwarded to: /booking/validateCruiseDeteails.jsp

gets forwarded to: /booking/validateUser.jsp

finally gets forwarded to: /booking/showCruiseDetails.jsp

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

get /booking/showCruiseDetails.jsp

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.

解决方案

On the target JSP use:

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

To find out what the original URL was.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值