0

At the beginning I'd like to point that I have done big research about it and couldn't find a solution. E.g I've read question on this site like:

How to get previous URL?

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

In those questions and other, I've read people say that request.getHeader("Referer"); is a good way to obtain previous url, but sometimes it doesn't work. That's it why I haven't found any solution what I have to do when it does not work.

I want like to obtain url from the previous page (e.g google.com or url from my app) when someone is accessing my app. The url of this page should be written in browser. Any idea how to obtain that?

Why do I need that? When someone is accessing my app with specific url (like localhost/page/something) and he is logged out, my app rederict him to login page and then after succesfull log in it goes to home page instead of previous url that he written. Sorry for my bad english.

Community
  • 1
  • 1
lukaszrys
  • 1,656
  • 4
  • 19
  • 33

1 Answers1

1

Easy, You can put the first requested url in a session-scope variable and retrieve It when you need.

request.getSession().setAttribute("firstURL", request.getRequestURL());
Farvardin
  • 5,336
  • 5
  • 33
  • 54