27. June, 2007

Why ServletRequest#getRemoteAddr() returns

Filed under: Java,Software Development — frightanic @ 00:39

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.



  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?

    Comment by Sven — 6. December, 2007 @ 17:46

  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.

    Comment by Sonal — 17. April, 2008 @ 07:22

RSS feed for comments on this post.

Create a free website or blog at

%d bloggers like this: