Link to home
Start Free TrialLog in
Avatar of merson
merson

asked on

problem with getting ip address in servlet


hi,

suppose i have an html file in
http://ip1/index.htm

and is sending a request to a servlet in another server with  ip2.

my problem is that how can i get ip1 from the request
within my servlet running on server ip2.

plz. note that i don't want to get the ip of client.

thanx in advance.
merson
Avatar of giamtrot
giamtrot

What do you want is the referer to the servlet but I think you can't get this information in the servelt automatically.
What you could try is to add this information to your first page, so that it's communicated to the servlet.

An example to do it via Javascript is above:

<html>
<head>
     <title>Untitled</title>
</head>

<body onload="document.ip.domain.value=document.domain">

<form name="ip" action="servlet">
<input type="Hidden" name="domain" value="">
<input type="Submit" onClick="alert(document.ip.domain.value); return false;">
</form>


</body>
</html>

It passes the name you used to get to the server (which is not always the ip address).

Cheers,

Raffaele
I think you should be able to get the referrer with the getHeader(String) method of HttpServletRequest.
Avatar of Mick Barry
If u don't want the ip of the client, and you don't appear to eant the ip of the web server, then whose ip are u after?
Avatar of merson

ASKER

hi,

i want to get the ip of the server on which my html file is
uploaded.

suppose i am having my html file index.htm on server1 with ip1 and my servlet is on server2 with ip2


merson



ASKER CERTIFIED SOLUTION
Avatar of rajesh_bala
rajesh_bala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept comment by rajesh_bala as answer.
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
lwinkenb
EE Cleanup Volunteer