从JSP访问资源文件 [英] Access resource file from JSP

查看:156
本文介绍了从JSP访问资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从位于Web/resources文件夹下的java类访问xml文件. 即

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

---网页
|
| --Web-INF
|
|-资源
| | -data.xml
|
|-其他jsps
---源文件夹
| -databean

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

我想从databean包下的类访问data.xml.是否有可能?怎么样?

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

推荐答案

使用

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

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

通常 Servlet ,而不是 JSP >.

这篇关于从JSP访问资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆