I have an application running under Jetty, and I want the application to return self referencing absolute URLs (when generating an RSS feed, so a client must be able to work without a "current URL" context).
The problem is that I don't know ahead of time under which host name the application will be deployed, and it is quite likely that it will be deployed in a virtual hosting environment where several host names are mapped to the same IP address. I've tried using HttpServletRequest.getLocalName()
, but that returns the resolved host name[1] for IP address on which the request was received (usually what is set in the local hosts file) and not the host name from the URL that the client specified in the HTTP request.
Basically I want to get what under CGI would be the environment variable SERVER_NAME
but it doesn't look like the Java API provides this. Any help will be appreciated.
[1] only if I'm lucky - on some setups it only returns the IP address.
-
Use
ServletRequest.getServerName()
to get the virtual host name from the "Host" header. This is equivalent to CGI'sSERVER_NAME
variable.Guss : Thanks :-) (that was a bit silly of me - I should have known this)
0 comments:
Post a Comment