How can i get the URL from which the user came to my Struts2 Action?
+1
A:
You can use the HTTP referrer:
String url = request.getHeader("referer");
However you need to be cautious as this is an optional value passed by the browser. In other words, not all clients will pass it to you.
A safer option is to pass the calling page as a hidden input value.
Pat
2010-09-07 12:35:41
+1
A:
Try:
request.getHeader("referer");
You can also create a hidden field in the form and then use a if statement to check and route accordingly.
I'd recommend you use the hidden field. While it is certainly more of a hassle it is also more reliable. The referer field can be stripped from the HTTP header by a proxy. In fact the browser isn't required to send the referer field in the header at all.
See a good discussion here. The above explanation is an extract from that discussion.
pavanlimo
2010-09-07 12:39:56