问题
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:
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.
来源:https://stackoverflow.com/questions/5186519/access-resource-file-from-jsp