English 中文(简体)
如何从Java Web应用程序中访问WEB-INF下的文件
原标题:How to acces a file under WEB-INF from a Java web application

你知道如何从我的应用程序中访问 WEB-INF/index 文件夹中的文件吗?我在使用 OpenCMS 来开发我的应用程序,我想要打开 WEB-INF/index 文件夹中位于 Lucene 搜索索引(借助 Lucene IndexReader 类)的 Lucene 搜索索引。Lucene jar 存储在 WEB-INF/lib 文件夹中。

最佳回答

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

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

然后使用常见的Java文件方法来读取它。

问题回答

你打算用那些索引文件做什么?

OpenCms使用Lucene作为其搜索引擎。如果索引文件位于“正确”的文件夹中,则可以在OpenCms中使用Lucene进行其他用途而不会出现任何问题。





相关问题
Lucene.NET in medium trust

How do I make Lucene.NET 2.3.2 run in a medium trust environment? GoDaddy doesn t like it the way it is.

Grails searchable plugin

In my Grails app, I m using the Searchable plugin for searching/indexing. I want to write a Compass/Lucene query that involves multiple domain classes. Within that query when I want to refer to the id ...

Search subset of objects using Compass/Lucene

I m using the searchable plugin for Grails (which provides an API for Compass, which is itself an API over Lucene). I have an Order class that I would like to search but, I don t want to search all ...

Lucene seems to be caching search results - why?

In my project we use Lucene 2.4.1 for fulltext search. This is a J2EE project, IndexSearcher is created once. In the background, the index is refreshed every couple of minutes (when the content ...

热门标签