On Mon, 14 Jan 2002, Fought,Tom wrote:

> Date: Mon, 14 Jan 2002 06:34:23 -0500
> From: "Fought,Tom" <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: directory of web application
>
> With all the tough questions here... this should
> be any easy one.
>
> How do I get the absolute directory or relative
> directory of where my webapp is running from
> a tomcat application?
>

The answer to this *sounds* easy:

  String documentRootPath = getServletContext().getRealPath("/");

but there is a gotcha.  If your web application is running directly out of
a WAR (as is the case in some containers, including Tomcat when you
configure it that way), this method will return null -- because there is
no such thing as the "directory of where my webapp is running from".

If you want to reference static resources inside the webapp, and have it
work portably in all container environments, you should use
ServletContext.getResource() or ServletContext.getResourceAsStream()
instead.

> Thanks
> Tom
>

Craig



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to