tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: ServletContextListener - how to detect http path of web application?
Date Wed, 21 Dec 2005 17:00:09 GMT
Tim is right, you can't do it directly.  You *might* be able to construct
it in a roundabout way though...

Let's assumg you know the method, http vs. https, and its always one or
the other.  Let's also assume that the <display-name> element in web.xml
names the application context (i.e., if the URL is http://myserver/myapp,
then <display-name>myapp<display-name>.  I believe the following (without
actually trying it) would work...

String s = "http://";
s += new InetAddress.getHostName();
s += "/" + servletContext.getServletContextName();

Kind of hack solution, but it might be OK for your application (assuming
it actually works!)

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Wed, December 21, 2005 6:22 am, Tim Funk said:
> There is no way to detect the contextPath on servletInit. It can only be
> done
> after the first request. (Using HttpServletRequest.getContextPath())
>
>
> -Tim
>
> Iain.Shepherd@barclayscapital.com wrote:
>> Hi,
>>
>> Apols for a newbie question, I didn't have much luck with the archives
>> or in Google.
>>
>> In my ServletContextListener.contextInitialized method, I need to detect
>> the public http path of my web app.
>> i.e. http://servername/approot/
>>
>> How can I do this?
>> event.getServletContext().getResource("/") gives me "jndi:/localhost/",
>> not very helpful.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message