Getting the URL of the calling page Java

血红的双手。 提交于 2019-12-08 17:37:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!