Access resource file from JSP

谁说胖子不能爱 提交于 2020-04-12 07:03:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!