aspose file tools*
The moose likes JSP and the fly likes server from which page accessed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "server from which page accessed" Watch "server from which page accessed" New topic
Author

server from which page accessed

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Hi,
How can I find out from which server my page was accessed? So, if someone logs in from server 23.44.11.9, I want to capture this IP address.
thanks,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
mounika paruchuri
Greenhorn

Joined: Feb 12, 2002
Posts: 26
Hi Alex,

I did not exactly understand your question but if you mean you want to know the server IP that answered the request then you can get it through 'request.getServerName()'.This method is in the interface ServletRequest.If not this and you want to find the Client IP then you can get it through 'request.getRemoteAddr()'. Hope this is of any help.
Mounika.
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
Use ServletRequest.getRemoteAddr(). From the API documentation:

Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request

Mark
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks guys. I also found this one: request.getRemoteHost().toString(); Is this the same as 'request.getServerName()?
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
According to my reading of the API documentation, getServerName() will return the name of the server that is running your servlet and getRemoteHost() returns the name of the client machine that issued the request. Note that getRemoteHost is not guaranteed to return a host name... it may return the same value as getRemoteAddr() if the host name of the client machine is not resolved by the servlet container.
I hope this helps,
Mark
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks a lot.
 
 
subject: server from which page accessed