I'm developing a web app with java servlet, I hope to get the user ip info by calling request.getRemoteAddr()
from inside processRequest(HttpServletRequest request,HttpServletResponse response)
.
But it returns a wrong IP. Since I'm not very knowledgeable about this area, I don't know what it is displaying, maybe a proxy, I got this:
RemoteAddr : 127.0.0.1 RemoteHost : 127.0.0.1 x-forwarded-for : null
127.0.0.1 is not my IP.
Yet when I go to: http://www.javascriptkit.com/script/script2/displayip.shtml
it will display the right one, since I'm using servlet, I don't have the .shtml to my dynamically generated html page, what can I do? And why the script on that site can display it correctly while request.getRemoteAddr()
can't do it?
Thanks for all the answers, I have a clue now, after deploying it to the server, it works as expected. Showed the correct address.
But even when I develop it on my local machine, how to ask it to display the absolute IP as if it running on a real server? Or is it doable?