How to acces a file under WEB-INF from a Java web application

强颜欢笑 提交于 2019-12-11 07:04:57

问题


Do you have any idea how to access files in WEB-INF/index folder from my application? I'm using OpenCMS for my application and I want to open a Lucene search index (with the help of Lucene IndexReader class) located at WEB-INF/index folder. Lucene jar is stored in WEB-INF/lib folder.


回答1:


If you want to lookup a file on the RFS (real file system) under the WEB-INF folder, you can get the path via:

String filepath = pageContext.getServletContext().getRealPath("/") + "WEB-INF" + java.io.File.separator + "index";

and then use the common java file methods to read it.




回答2:


What do you intend to do with those index files?

OpenCms uses Lucene for its search engine. It is possible to use Lucene from within OpenCms for other purposes without any hassle if the index files are in the "correct" folder.



来源:https://stackoverflow.com/questions/2340744/how-to-acces-a-file-under-web-inf-from-a-java-web-application

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