How to get previous page URL from request using a servlet
12,299
Write in your Servlet the following code
String url = request.getHeader("referer");
This worked in my case.Hope it works for you as well
Author by
Jessie
Updated on June 04, 2022Comments
-
Jessie almost 2 years
How do I get the previous page URL from request using a servlet. For example, I'm from the index.html and I submitted a form from index, how do I get the index.html URL and use it in a servlet?
request.getRequestURL()
getRequestURL doesn't work since it only returns the URL of the servlet.
-
Sergio A. about 4 yearsI am currently working on a Rails project in which we have this need too. After some time researching, there is no guarantee about the referer header itself. Different web-browsers set this header as its own criteria. This is not a definitive workaround because of possibles values in third party websites. Be aware of this limitations in case they are relevant to you. developer.mozilla.org/es/docs/Web/HTTP/Headers/Referrer-Policy