简体   繁体   English

Eclipse动态Web项目:我应该在哪里放置资源文件

[英]Eclipse dynamic web project : where should I put resource files

I am trying to make a eclipse dynamic web project. 我正在尝试制作蚀动态Web项目。 I have tried putting a pdf file in the "WEB-INF" directory of the project. 我尝试将pdf文件放入项目的“ WEB-INF”目录中。 But when I try to obtain a input stream using 但是当我尝试使用获取输入流时

InputStream inStream = getServletContext().getResourceAsStream("/WEB-INF/mypdf.pdf");

I get inStream = null . 我得到inStream = null I also tried putting the mypdf.pdf file in the directory the class from where I am trying to obtain the input stream and use 我还尝试将mypdf.pdf文件放在我试图从中获取输入流并使用的类的目录中

InputStream inStream = getServletContext().getResourceAsStream("mypdf.pdf");

again, it returns inStream = null 再次返回inStream = null

Any suggestion? 有什么建议吗?

You could use 你可以用

this.getClass().getResourceAsStream("mypdf.pdf");

if the file is in directory where your class is. 如果文件位于类所在的目录中。

getResourceAsStream在类路径上搜索文件

   InputStream stream = this.getClass().getClassLoader().getResourceAsStream("your pdf file");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM