**request.getRequestURL()、request.getRequestURI()**均不行,获取的是请求的地址。
使用**request.getHeader("Referer")**就可以正确的获取到之前请求的页面URL地址。
Http协议中定义了头部的属性,其中有一个参数"Referer"记录请求之前的页面地址。
In the most common situation this means that when a user clicks a link in a web browser, the browser sends a request to the server holding the destination webpage. The request includes the referrer field, which says the last page the user was on (the one where he/she clicked the link).
浏览器会将请求之前的页面地址记录并发到请求头去,请求中包含了referrer这个属性。
Referrer logging is used to allow websites and web servers to identify where people are visiting them from, for promotional or security purposes. Referrer is a popular tool to combat cross-site request forgery, but such security mechanisms are weakened by the ease of disabling or forging a referrer. The referrer is widely used for statistical purposes.
referrer有效的阻止了跨站攻击(XSS)。
If a website is accessed from a HTTP Secure (HTTPS) connection and a link points to anywhere except another secure location, then the referrer field is not sent. The upcoming standard HTML5 will support the attribute/value rel = "noreferrer" in order to instruct the user agent not to send a referrer.
Https暂不支持referrer,HTML5将会有更多的支持。
参考: http://en.wikipedia.org/wiki/HTTP_referrer