• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to know ip address in JSP

 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..
i have a JSP program .. in which before inserting a record i need to capture the IP address of the machine from where the record is being inserted ....can any one please help me on that..!!!
Thanxs in advance for help..!!!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request object has the getRemoteAddr method.
Look at the javax.servlet.ServletRequest JavaDocs
Bill
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i use out.print( request.getRemoteAddr() );out.print(request.getRemoteHost() ); method...it gives me the local host ipaddress .... but it doesnot give me the machines ipaddress....how do i get the machine ipaddress of a user ... who is accessing my web pages.... please help..!
thanxs..!
 
Amit KumarS
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rekha,
request.getRemoteAddr() is the method to do that as william said. you might be trying to access the JSP page from same machine on which you server is. in that case of course the IP address returned will the of the same localhost machine.
try acessing the page from some other machine other then server and then see what is gives.
Bye and best of luck
Amit
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeh i got it using
out.print( java.net.Inet4Address.getLocalHost().getHostAddress() );
.
thanxs for all the help...!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic