my2cents

27. June, 2007

Why ServletRequest#getRemoteAddr() returns 127.0.0.1

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

http://localhost:port/

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

http://systemname:port/

Yet another lesson learned I’ll never forget.

Advertisements

2 Comments

  1. Hi
    I have the same problem and I couldn’t solve it with using your solution… 😦
    I always get the 127.0.0.1 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 WordPress.com.

%d bloggers like this: