You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Julia Kuznetsov <ju...@modusmedia.com> on 2001/06/27 22:27:21 UTC
Relative file path
Is there a way to use relative file path (ex. "examples/docs/test.xml") when
accessing(reading etc.) it from servlet rather then absolute (ex.
"D:\smthg\app\docs\test.xml") path.
Ex. : I have web app "examples" that mapped to d:\smthg\app.
My file "test.xml" is in d:\smthg\app\docs.
Can I access it using "examples/docs/test.xml? If yes, how?
Right now it's translating it to Tomcat bin dir:
"D:\jakarta-tomcat-3.2.2\bin\examples\docs\test.xml"
Sorry, I'm new to Appache-Tomcat world...
Re: Relative file path
Posted by Bo Xu <bo...@cybershop.ca>.
Julia Kuznetsov wrote:
> Is there a way to use relative file path (ex. "examples/docs/test.xml") when
> accessing(reading etc.) it from servlet rather then absolute (ex.
> "D:\smthg\app\docs\test.xml") path.
>
> Ex. : I have web app "examples" that mapped to d:\smthg\app.
> My file "test.xml" is in d:\smthg\app\docs.
> Can I access it using "examples/docs/test.xml? If yes, how?
> Right now it's translating it to Tomcat bin dir:
> "D:\jakarta-tomcat-3.2.2\bin\examples\docs\test.xml"
>
> Sorry, I'm new to Appache-Tomcat world...
Hi :-) you can put testApp.properties in myapp/WEB-INF/, and use
the following relative path to access it:
InputStream is = this.getServletContext().
getResourceAsStream("/WEB-INF/testApp.properties");
(normally), you also can put testApp.properties is in
myapp/WEB-INF/classes, and use the following relative path to
access it:
- InputStream is = this.getClass().
getResourceAsStream("testApp.properties");
- InputStream is = Thread.currentThread().getContextClassLoader().
getResourceAsStream("testApp.properties");
Bo
June 27, 2001