• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting remote address

 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have tried every way to use the servlet API try to get what the user typed in the browser as the their host name. I cant seem to find anything that helps! The most closest 2, request.getRemoteAddr() and request.getRemoteHost() only gets what's set in the server, not what the user typed in.
Can someone shed some light please???
Thank you very much!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to get what the user typed in the browser as the their host name

Could you be a bit clearer on what you are after?
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say, if user typed in http://hostName/myPage.jsp I want to get the hostName they typed in. This is for internal use and therefore I cant use request.getRemoteAddr. That hostName is typically set in the user's host files (on windows) that maps to the server's IP. I cant use the IP if the users dont want to (you know, clients are a bit too demanding sometimes).
Hope this is clear enough. Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if user typed in http://hostName/myPage.jsp I want to get the hostName they typed in.

Ok, that's what was confusing. getRemoteAddr() will return the IP of the client and has nothing at all to do with the URL that they typed in. What is it about getRequestURL() that doesn't do it for you?
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It returns my IP and Port number where the servlets are
I am running Tomcat as the servlet engine and IIS web server.
So the URL that access the page is different from where the servlets are.
e.g. http://hostname/mypage/
will mapped to http://127.0.0.1:8080/mypage this is not suppose to show
So I want to getSomeFunction() that returns "hostname" so I cant use that
host = "hostname";
for page redirection sendRedirect(host + "/error.html");
Am I making sense? It's kinda hard to explain by writing.
[ February 02, 2004: Message edited by: Anna Kafei ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It returns my IP and Port number where the servlets are

No, getRequestURL() will return the URL information of the request. Please see the Javadoc reference.
But, I'm still confused as to what you are trying to do in the first place. If you want redirect to the same server/host to which the request was originally made, simply specify a relative URL (no server name).
For example, if the request was to http://www.someserver.com/whatever, a redirect to "/whatever2" will cause the redirect to request http://www.someserver.com/whatever2.
[ February 02, 2004: Message edited by: Bear Bibeault ]
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No, getRequestURL() will return the URL information of the request. Please see the Javadoc reference.
But, I'm still confused as to what you are trying to do in the first place. If you want redirect to the same server/host to which the request was originally made, simply specify a relative URL (no server name).

It returns the location where the page is served, not what the user has typed in...
ie, it returns http://192.168.4.20:8080/mypage.jsp instead of http://myhost/mypage <-- in browser location

For example, if the request was to http://www.someserver.com/whatever, a redirect to "/whatever2" will cause the redirect to request http://www.someserver.com/whatever2.

if I dont specifiy the host name it redirect to http://192.168.4.20:8080/error.jsp instead of http://myhost/error
It is not www, this is all internal. ie, serves under http://192...
There should be a header containing what the user's typed in, just, there isnt one. Guess have to out.println("window.location('/error.jsp')"); or something... get go around that if JSP dont have that feature...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!