Guillaume Barreau wrote:

> Dear tomcat users,
>
> How do I find the root directory of the application to which a servlet belongs?
> I know that the following works:
>         getServletContext().getRealPath("")
>
> But the documentation on getRealPath warns me that this is not going to work if
> my application is deployed as a war file.
> Is there a way of doing this that would work with war?
> Say I want to access file foo.txt that is in the root directory of my
> application. How do I get to this file if the application is deployed as a war
> file?
>

To access a resource within your web app, in a manner that works even on servlet
containers that run directly from a WAR, do something like the following:

    InputStream is =
      getServletContext().getResourceAsStream("/WEB-INF/myprops.properties");

Now, you can load the "myprops.properties" resource in a manner that is totally
portable.

>
> Thanks for any help,
>
> Guillaume Barreau
>

Craig McClanahan



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

Reply via email to