File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Implementation of getServerName in web servers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Implementation of getServerName in web servers" Watch "Implementation of getServerName in web servers" New topic

Implementation of getServerName in web servers

Jody Seigle

Joined: Sep 29, 2000
Posts: 24
I am using Netscape Enterprise Edition 6.01 and attempting to access a Java applet. Some machines are able to see the site using a hostname (myserver) while others can only resolve it using the IP address. However, I have noticed that even though a user enters the IP address in the browser URL, a servlet calling the getServerName() method of HttpServletRequest returns the hostname of the machine (myserver).
My question is how do common webservers implement the getServerName() method. I have found that some use the Host request-header value passed by the browser. Is there a way to determine what my browser is passing for this header field?
Steve Leach
Ranch Hand

Joined: Sep 24, 2003
Posts: 46
I have had similar problems, specifically with Apache forwarding requests to Tomcat. Apache wasn't sending the requested host name through to Tomcat, which was then using the local machine hostname rather than the name the client requested.
will return the host name requested by the client, IF it was set by the browser. If the browser doesn't set that header then I don't think there is anything you can do.
I agree. Here's the link:
subject: Implementation of getServerName in web servers
jQuery in Action, 3rd edition