• Post Reply Bookmark Topic Watch Topic
  • New Topic

Knowing Client machine IP address through servlets  RSS feed

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
Can anyone please tell me that can I know the client address which is invoking the servlet in the server-side.
Any help will be highly appreciated.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletRequest interface has a method called getRemoteHost() that should return the IP address.
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the IP Address you should probably use the getRemoteAddr() method on the request rather than the getRemoteHost() method. The getRemoteHost() method may return the NAME of the host rather than the IP address if it can be determined.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. That's the one. I looked right over it when I was looking at the API.
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you. Thank you very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!