Iain-
Unless of course you only make this assignment in the init method
Thanks,
Martin-
----- Original Message ----- 
From: <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
Sent: Wednesday, December 21, 2005 12:17 PM
Subject: RE: ServletContextListener - how to detect http path of web 
application?


Thanks, I might try that.

I already made a javax.servlet.Filter, that catches the first request to
the server, calls HttpServletRequest.getContextPath(), and stores the
result.

Of course the Filter actually gets hit on *every single request* to the
server. You might call it a brute force solution :-)

Iain


-----Original Message-----
From: Frank W. Zammetti [mailto:[EMAIL PROTECTED] 
Sent: 21 December 2005 17:00
To: Tomcat Users List
Cc: Tomcat Users List
Subject: Re: ServletContextListener - how to detect http path of web
application?


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: [EMAIL PROTECTED]

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
>
> [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



------------------------------------------------------------------------
For more information about Barclays Capital, please
visit our web site at http://www.barcap.com.


Internet communications are not secure and therefore the Barclays 
Group does not accept legal responsibility for the contents of this 
message.  Although the Barclays Group operates anti-virus programmes, 
it does not accept responsibility for any damage whatsoever that is 
caused by viruses being passed.  Any views or opinions presented are 
solely those of the author and do not necessarily represent those of the 
Barclays Group.  Replies to this email may be monitored by the Barclays 
Group for operational or business reasons.

------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to