tags:

views:

196

answers:

2

I need to log URLs that are linking to my site in a Java Servlet.

+3  A: 

It's available in the HTTP referer header. You can get it in a servlet as follows:

String referrer = request.getHeader("referer"); // Yes, with the legendaric misspelling.

You however need to realize that this is a client-controlled value and can be spoofed to something entirely different or even removed. Thus, whatever value it returns, you should not use it for any business purposes, but only for pure statistics.

BalusC
thanks for the super quick response! :D
shane
You're welcome.
BalusC
+1  A: 

The URLs are passed in the Request. Request.getRequestURL().

If you mean other sites that are linking to you? You want to capture the HTTP Referrer, which you can do by calling:

request.getHeader("referer");
Chris Kaminski