Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getResourceAsStream() just retrieves files from Jar?

843841Nov 28 2005 — edited Nov 29 2005
Hello all,

I have a Servlet 2.4/JSP 2.0 App running on Tomcat 5.5.9 on GNU/Linux. When I want to load a file resource from within my webapp, I only manage to do so from Jar files within my app.
As soon as I want to load static files from my webapp, it fails. I tried to load file from under WEB-INF and the context root, e.g.:

/sample.txt
and
/WEB-INF/sample.txt

I tried to do so in different contexts:

SomeBean.getClass.getResourceAsStream()
SomeBean.getClass.getClassLoader().getResourceAsStream()
...getSession().getClass().getResourceAsStream()
...getSession().getClass().getClassLoader().getResourceAsStream()
...getSession().getServletContext().getClass().getResourceAsStream()
...getSession().getServletContext().getClass().getClassLoader().getResourceAsStream()

etc. but nothing works.
I cannot dig further into it. Are there any limitations not mentioned in the API docs? I googled around but did always find examples not telling where exactly the file is in the setup. Only on Oracle.com I found a sample where they load a file from below /WEB-INF...

I also tried to pass the app's context name and everything w/ and w/o leading slash. I think iit has to do with the "package" name mentioned in the docs, cos the Jar file shares the same base package like my Servlet...

Any ideas?
Thanks for any hints,
Regards,
Timo
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 27 2005
Added on Nov 28 2005
4 comments
1,116 views