Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the URL of the calling page Java

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.

like image 552
Krt_Malta Avatar asked Mar 11 '11 15:03

Krt_Malta


2 Answers

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

like image 111
Eran Medan Avatar answered Sep 22 '22 16:09

Eran Medan


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.

like image 24
Shamit Verma Avatar answered Sep 22 '22 16:09

Shamit Verma