views:

50

answers:

3

How can I get the IP address of the server from a JSP page?

Right now, all I can do is request.getLocalName(), which returns the server name, not the IP address?

A: 
String sIPAddr = request.getRemoteAddr();
Abhijeet Pathak
A: 

request.getRemoteAddr()

Aaron Saunders
+1  A: 

Actually, for the IP address of the server, you need to use

String serverIP = request.getLocalAddr();
ig0774
Thanks. Why didn't I see that on the javadoc? @_@
portoalet
@portoalet: May not have been overlooking it. getLocalAddr() was added for the 2.4 version of the servlet spec (I believe the first result in Google is the Javadoc for Java EE 1.3)
ig0774
@ig0774 Ok that explains it.
portoalet