如何从Java Web应用程序访问WEB-INF下的文件 [英] How to acces a file under WEB-INF from a Java web application

查看:699
本文介绍了如何从Java Web应用程序访问WEB-INF下的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否知道如何从我的应用程序访问WEB-INF/index文件夹中的文件?我正在为我的应用程序使用OpenCMS,我想打开一个位于WEB-INF/index文件夹中的Lucene搜索索引(借助于Lucene IndexReader类). Lucene jar存储在WEB-INF/lib文件夹中.

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.

推荐答案

如果要在RFS(真实文件系统)上的WEB-INF文件夹下查找文件,可以通过以下方式获取路径:

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";

,然后使用常见的java文件方法读取它.

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

这篇关于如何从Java Web应用程序访问WEB-INF下的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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