Solved

problem with getting ip address in servlet

Posted on 2001-08-02
6
191 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
Comment Utility
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
Comment Utility
I think you should be able to get the referrer with the getHeader(String) method of HttpServletRequest.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:merson
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now