users@glassfish.java.net

Re: How to get endpoint URL from ServletContext

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 11 Mar 2010 21:17:15 -0500

Hi Jan,

Thank you for your kind help.

The hostname can be looked up. But How do I get the protocol scheme and
port reliably?
I am surprised that this seems so hard and that ServletContext does not
have the endpoint readily available as a complete URL.

Is this not something that is needed very frequently?
Is there a better way to do what I am trying to do?

Thanks for any further help on this.

On 03/11/2010 07:04 PM, Jan Luehe wrote:
>
> Try using ServletContext#getContextPath, which returns an
> application's prime or preferred context path (in case the application
> has been deployed to more than one context root), and prepend it with
> the desired scheme, domain (host) name, and port in order to form a
> complete URL.
>

-- 
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com