6

I need the URL from which my web app is called. For eg:- If there is a link to my site foo.com from stackoverflow.com, I need the stackoverflow link in web app(managed bean).

All helps appreciated, thanks.

Reporter
  • 3,897
  • 5
  • 33
  • 47
Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40

2 Answers2

14

Not always filled, but you can use:

HttpServletRequest.getHeader("Referer");

Note: The spelling error is on purpose. For an explanation see here.

nfechner
  • 17,295
  • 7
  • 45
  • 64
  • I had been trying with Referer for some time now, but its returning null. FacesContext.getCurrentInstance().getExternalContext() .getRequest().getHeader("Referer") – Johny T Koshy Aug 09 '11 at 10:53
  • 2
    As I said, it is not always filled. How are you creating the request? Using a browser? By clicking a link or by typing the URL? – nfechner Aug 09 '11 at 10:55
  • 1
    @user757071 Try using a browser debugging tool such as Firbug for Firefox. It can show you all the request and response headers. You can see if the `Referer` header is present in the request after you have clicked a link. – Qwerky Aug 09 '11 at 11:05
  • @Qwerky, thanks for mentioning firebug. Referer header was not present. – Johny T Koshy Aug 09 '11 at 13:47
  • Sorry, there is no other way. And it cannot be otherwise anyway, as not all URL requests are the result of someone clicking on a link. – nfechner Aug 09 '11 at 14:02
1

By checking the HTTP Referrer you can see from which site the request for your site originated.

Deepansh Gupta
  • 593
  • 4
  • 9