问题
To put you in the picture, we're using a custom server based on Tomcat 6.0.29. We're developing using Java and Spring.
Let's say I have a link which takes you from http://localhost/display to http://localhost/save. In the controller of http://localhost/save, can I get http://localhost/display from the request parameter somehow?
request.getRequestURL() seems to get the url of the current page.
回答1:
This should give you the referring page (is most cases)
request.getHeader("referer");
See here for details http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z14
And here for more details on the request API
回答2:
You can use "referrer" header to check the page from where the request was made. However it would not work in all cases.
One way could be to set a cookie on http://localhost/display and unset it on http://localhost/save. That way you would know if user visited display prior to save.
来源:https://stackoverflow.com/questions/5274869/getting-the-url-of-the-calling-page-java