Solved

problem with getting ip address in servlet

Posted on 2001-08-02
6
195 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert from a json string array to a Java object 3 65
Setup GlassFish 4 37
JDBC performance 8 29
Code Coverage and Coding Standards 2 51
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

730 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