How to retrieve the IP address or the hostname of the client which is accessing a servlet?

JIA Java Italian Association

Wow, it's incredible, but I've just opened the javadoc of Servlet 2.2 and I've found these two incredible methods of the javax.servlet.ServletRequest:

getRemoteAddr() Returns the Internet Protocol (IP) address of the client that sent the request.

getRemoteHost() Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determinated.


It's incredible how many strange things you can find when you decide to RTFM.
Regards.

[See also What are the Servlet equivalents to all the CGI environment variables? ]

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact