This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
Consider Paul's rocket mass heater.
subject: Implementation of getServerName in web servers
Similar Threads
Getting CommunicationException
Getting the Server Name from request object
RMI callback
inetaddress dns?
Determining IP address I'm being communicated over