spring mvc tracing the referrer page
jakarta-ee, java, spring, spring-mvc
Solution
you can use two below methods:
request.getAttribute("javax.servlet.forward.request_uri")
or
request.getHeader("Referer");
In above methods you are trusting the browser behavior and also the container which make the request object available to you. I don't know why you don't want to use this method.
Or
you can get the current page/serlvet url save it in the session and use it in the second page.
String requestUrl=request.getRequestURL();
session.setAttribute("pervious_page",requestUrl);
Then in the second page:
session.getAttribute("pervious_page");
Problem
In annotation based spring controller. if a user was on `url.com/first/page` and clicked a link or submitted a form pointing to say `url.com/second/page` . How to make the `second/page` know the `url of /first/page` so that the `second/page` can 1) `redirect` the user to the `first/page` again when the form values are processed. 2) or show a b`ack button link` to the `/first/page`? Edit 1 -- `request.getHeader('Referer')` is another but those I `think` are browser based on the mercy of browser. If the browser dont do it, we cant know. I wanted a way which is application wide. some how passing the url from one page to another Edit 1 end --