如何获取客户端的URL [英] How to get the url of the client

查看:427
本文介绍了如何获取客户端的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将请求从Display.jsp发送到TrialShow.jsp页面,但是每当我在TrialShow JSP页面中调用${pageContext.request.requestURL}时,都会得到http://localhost:8081/newjsp1/TrialShow.jsp作为输出.如何在TrialShow JSP页面中显示http://localhost:8081/newjsp1/Display.jsp?

I'm sending the request from Display.jsp to TrialShow.jsp page, but whenever I call ${pageContext.request.requestURL} in TrialShow JSP page, I'm getting http://localhost:8081/newjsp1/TrialShow.jsp as an output. How can I display http://localhost:8081/newjsp1/Display.jsp in TrialShow JSP page?

推荐答案

因此,您想要通过一个有价值的HTTP请求调用当前页面的页面的URL吗?我假设没有转发的方法,因为您通常不为此使用JSP(因为它可能会产生IllegalStateException: Response already committed),而且对于转发,您的要求将按照您想要的方式工作.

So you want the URL of the page which called the current page by a fullworthy HTTP request? I assume that there's no means of a forward, because you usually don't use JSP for this (as it would potentially produce IllegalStateException: Response already committed) and also, with a forward your requirement would have just worked the way you want.

然后最简单的方法和最好的选择就是获取HTTP Referer 标头(是,包括传说中的错字).您可以按如下方式在EL中获得它:

The easiest way and your best bet is then getting the HTTP Referer header (yes, including the legendary typo). You can get it in EL as follows:

${header.referer}

我说最好的选择",因为不需要客户填写引荐来源标头.大多数浏览器都会将它们发送出去,但是请记住,此值完全可以由客户端控制,因此客户端(或客户端安装的任何软件,以及某些特定的Norton软件,例如已知的示例)都可以欺骗甚至完全删除该值.标头值.

I said "best bet", because clients are not required to fill the referrer header. Most browsers will send them along, but keep in mind that this value is fully controllable by the client, thus the client (or any of the client-installed software, with some specific Norton software as known example) can spoof or even fully remove the header value.

一种更可靠的方法是让原始页面将其URL作为(隐藏的)请求参数传递.例如

A bit more reliable way is to let the original page pass its URL as a (hidden) request parameter. E.g.

<input type="hidden" name="from" value="${pageContext.request.requestURI}">

通过这种方式,下一页即可访问

This way it's accessible in next page by

${param.from}

我说的是位",因为客户端仍然可以更改它,但是现在您不再依赖于客户端特定的环境了.您仍然需要记住,不要将此值用于业务目的.最高将其用于统计或调试.

I said, "bit", because the client can still change it, but now you're not dependent on the client specific environment anymore. You still need to keep in mind that you shouldn't use this value for business purposes. Use it at highest for statistics or debugging.

这篇关于如何获取客户端的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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