Access resource file from JSP

7.5k views Asked by At

I want to access xml files from java class, lying under web/resources folder.. i.e

---Web pages
|
|--Web-INF
|
|-resources
| |-data.xml
|
|-other jsps
---Source Folder
|-databean

I want to access data.xml from a class under databean package. Is it possible? How?

1

There are 1 answers

4
BalusC On

Use ServletContext#getResource() or #getResourceAsStream() to obtain resources which are available in the webcontent.

InputStream input = getServletContext().getResourceAsStream("/WEB-INF/resources/data.xml"); 

You however normally do that in a Servlet, not a JSP.