Solved

problem with getting ip address in servlet

Posted on 2001-08-02
6
193 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 100 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
groupNoAdj 7 96
eclipse package explorer vs project explorer view 2 133
Spring Framework HTTPSession management 1 36
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

777 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