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
2010-04-15 21:09:53
thanks for the super quick response! :D
shane
2010-04-15 21:12:09
You're welcome.
BalusC
2010-04-15 21:19:36
+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
2010-04-15 21:11:17