Milt Epstein wrote:
> Checked the archives and dejanews, and couldn't find an answer to this
> one.
>
> A machine can have more than one FQDN, so the name used in a URL might
> be different from the "actual" server name (I don't mean the canonical
> name, but rather the name the web server knows -- this can be
> configured, in NES, at least).
It is also configurable in lots of other web servers; for example, with
Apache's <VirtualHost> capability. The web server tells requests apart, even
though they come in on the same IP address, by the presence of a "Host:" HTTP
header.
> CGI apparently provides the
> environment variables HTTP_HOST and SERVER_NAME to distinguish between
> these (HTTP_HOST actually includes the port, while SERVER_NAME does
> not). I could only find getServerName() in the JSDK API. This
> apparently corresponds to HTTP_HOST (without the port).
The ServletRequest.getServerName() method actually corresponds to SERVER_NAME
... the name of the virtual host that this request asked for. You can get the
port number with getServerPort() if you need it, such as to reconstruct an
absolute URL. The servlet API itself does not have a call for the canonical
host name.
> Is there any
> way I can get both of these names in a servlet?
>
> I thought of InetAddress.getLocalHost(), but I don't think that will
> work. I'm guessing that will return the canonical name of the server,
> which is not necessarily the same.
>
The value returned by InetAddress.getLocalHost().getHostName() should return
the canonical host name that would correspond to the HTTP_HOST variable minus
the port number, which will be the same for both. As above,
ServletRequest.getServerName() returns the name that matches SERVER_NAME.
>
> Milt Epstein
Craig
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html