my dog learned polymorphism*
The moose likes Servlets and the fly likes HttpServletRequest - get previous page url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest - get previous page url" Watch "HttpServletRequest - get previous page url" New topic
Author

HttpServletRequest - get previous page url

Brian Hsu
Greenhorn

Joined: Aug 04, 2011
Posts: 12
HttpServletRequest has methods to get the current page's URL. Is it possible to get the previous like Apache log's referrer? Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, except the name of the HTTP header you're looking for is "Referer" (not spelled the way you might expect). You can get header values from the request.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Be aware that it is not guaranteed to be set, or to be set correctly.

Why do you need this? If you are trying to make decisions regarding what to do based on where you came from... don't!



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Hsu
Greenhorn

Joined: Aug 04, 2011
Posts: 12
Bear Bibeault wrote:Be aware that it is not guaranteed to be set, or to be set correctly.

Why do you need this? If you are trying to make decisions regarding what to do based on where you came from... don't!



I'm trying to use this for debugging. Currently I'm getting lots of error notification emails from an URL and I'd like to find out where/how users got to that page from.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Ah, ok. I was hoping it wasn't something along the lines of what was being discussed here.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

For debugging, you should also be able to use tools such as HttpFox to observe the headers without having to change any code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletRequest - get previous page url
 
Similar Threads
url rewrite filter
Cookies
How can we get URL in Spring framework
can I get brower's previous url?
Any idea when do we get SCBCD logo