?
Solved

problem with getting ip address in servlet

Posted on 2001-08-02
6
Medium Priority
?
198 Views
Last Modified: 2013-11-24

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
0
Comment
Question by:merson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:giamtrot
ID: 6343644
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
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6343810
I think you should be able to get the referrer with the getHeader(String) method of HttpServletRequest.
0
 
LVL 92

Expert Comment

by:objects
ID: 6343813
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?
0
Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

 

Author Comment

by:merson
ID: 6344680
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



0
 
LVL 10

Accepted Solution

by:
rajesh_bala earned 400 total points
ID: 6354748
Hi,
  Use HttpServletRequest.getRequestURL().
 This will give u the address. I think u know how to convert this to the ip address using the java.net package.

regards
Rajesh
0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 8895320
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
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question