tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Can't find ServletContext.getContextPath()
Date Mon, 06 Aug 2007 15:33:42 GMT
Hash: SHA1


aladdin wrote:
> I have the following two lines of code in a context listener:
> 	ServletContext sc= e.getServletContext(); // e is a ServletContextEvent
>         log.write("AppInitializer::ContextInitializer: context name='" + sc.getServletContextName()
+ "'");
>         log.write("AppInitializer::ContextInitializer: context path='" + sc.getContextPath()
+ "'");
> When I try to compile this, I get:
> ./src/utils/ cannot find symbol
> symbol  : method getContextPath()
> location: interface javax.servlet.ServletContext
>         log.write("AppInitializer::ContextInitializer: context path='" + sc.getContextPath()
+ "'");
> Why is it not finding the function (and only the function) ServletContext.getContextPath()?
 It's the first time I've used this function, but it is typed (I think; maybe I'm going crazy-
too much programming, ya' know) exactly as it appears in the Sun J2EE documentation.

Unless you can use a Servlet 2.5-spec container, I don't think you can
do what you want to do. It looks like you want the webapp's context path
 for logging (i.e. the "/myWebapp"), but there's no access to it before
the 2.5-spec (though I'm not sure why... it seems like a basic piece of
information that should not require a request to fetch).

Since it's just for logging, I'm sure that
ServletContext.getServletContextName will meet your needs... you'll just
have to set a <display-name> in your deployment descriptor (web.xml).

- -chris
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message