Why ServletRequest#getRemoteAddr() returns

When I found the reason why my Servlet container returns the “wrong” remote address I had to smite my forehead – long and hard. As so often the container is right and I was simply on the wrong track. It’s soooo obvious, Jesus…

If you access your application using the URL


, you will get the remote address as (local host address i.e. loop back address). Instead, try accessing the URL using your system/server name to get the desired output


Yet another lesson learned I’ll never forget.

2 thoughts on “Why ServletRequest#getRemoteAddr() returns

  1. Hi
    I have the same problem and I couldn’t solve it with using your solution… 🙁
    I always get the as remote address. Do you have any other idea?

  2. I think getRemoteAddr() returns the ip of the client, not the server. localhost/servername in your case denote the server, and the getRemoteAddr() should not be affected by this.

Leave a Reply