Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the previous page URL from request in servlet after dispatcher.forward(request, response)

I'm using the servlet which redirects me with the help of

dispatcher.forward(request, response);

in the end. But after this I want to get the page(path) from which I was redirected to use it in next servlet command(to go to previous page). How could I get it? Or previous URL is not contained in request parameters and I should add it myself? Will be very grateful for your help.

like image 622
And Avatar asked Dec 21 '11 16:12

And


2 Answers

String referer = request.getHeader("Referer"); response.sendRedirect(referer);

SEE: Link to forum answer

like image 163
Gyan Avatar answered Sep 27 '22 21:09

Gyan


Try using

request.getAttribute("javax.servlet.forward.request_uri")  

See
https://tomcat.apache.org/tomcat-9.0-doc/servletapi/constant-values.html
and
How to get the url of the client

like image 29
rickz Avatar answered Sep 27 '22 22:09

rickz