You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by J Malcolm <te...@malcolms.com> on 2005/04/05 05:23:16 UTC

Accessing the context path within a Servlet/JSP

I have looked at the JavaDocs, but I can't find a method that will give me
the context path for a web app:

(i.e. <Context path="/abcxyz" docBase="...)  All I want is the "/abcxyz"
string precisely as defined in the context tag.

I have tried getPath() from the servletContext, but it returns part of the
host name as well.  That doesn't make sense either, but that's the way it's
working for me... It returns "jndi:" for the protocol (???) Am I doing
something else wrong here?

I found the getServletContextName() method.  But that is an optional
parameter on the context tag, and I can't risk using something that might
not be defined.

I'm currently parsing up the URL object returned from
servletContext.getResource("/");  But this is a hack.  Surely there is a
better way to get the root URL context for a web app... (?)

Suggestions??  (BTW... Tomcat 5.5.7)

Thanks.

Jerry




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


Re: Accessing the context path within a Servlet/JSP

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
See HttpServletRequest.getContextPath()

J Malcolm wrote:
> I have looked at the JavaDocs, but I can't find a method that will give me
> the context path for a web app:
> 
> (i.e. <Context path="/abcxyz" docBase="...)  All I want is the "/abcxyz"
> string precisely as defined in the context tag.
> 
> I have tried getPath() from the servletContext, but it returns part of the
> host name as well.  That doesn't make sense either, but that's the way it's
> working for me... It returns "jndi:" for the protocol (???) Am I doing
> something else wrong here?
> 
> I found the getServletContextName() method.  But that is an optional
> parameter on the context tag, and I can't risk using something that might
> not be defined.
> 
> I'm currently parsing up the URL object returned from
> servletContext.getResource("/");  But this is a hack.  Surely there is a
> better way to get the root URL context for a web app... (?)
> 
> Suggestions??  (BTW... Tomcat 5.5.7)
> 
> Thanks.
> 
> Jerry
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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