I have a Spring (Java) website that uses Kemp Technologies' LoadMaster as the balancer, which sits before my web servers.
I am able to get the right IP address of a visitor at any page via:
request.getRemoteAddr()
However, I am not able to get the correct domain of the referrer. Here is what I did:
I have the following code in a HandlerInterceptorAdapter, which is called for each web request. The code is to check whether a particular session variable exists. If yes, no action. If no, record the referrer's domain in session.
HttpSession session = request.getSession(); String value = (String) session.getAttribute("referrer"); if (value == null) { String scheme = request.getScheme(); String serverName = request.getServerName(); int portNumber = request.getServerPort(); String url = scheme +"://"+serverName+ (portNumber == 80? "": portNumber); session.setAttribute("referrer", url); }
In other pages when I need the referrer's domain, I have the following:
String value = (String) request.getSession().getAttribute("referrer");
The problem is that the value I got is always my own domain (ex. http://www.example.com).
Where have I gone wrong?