【发布时间】:2016-08-04 13:24:34
【问题描述】:
我在访问 WebContent 文件夹中的文件时遇到了问题(在这种情况下,我需要访问 WEB-INF 文件夹)
这是我尝试访问 WEB-INF 文件夹的地方。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dbPath = "/WEB-INF/musicDb.db";
String xmlPath = "/WEB-INF/musicDb.xml";
ServletContext context = null;
context = getServletContext();
String test = context.getRealPath(xmlPath);
File f = new File(test);
if (f.exists()) {
}
}
我在 WEB-INF 文件夹中准备好了 musicDb.xml,但是,通过调试,我总是得到这个路径
{my local project path}/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/9321A1/WEB-INF/musicDb.xml
我怀疑这与构建过程中未包含 WebContent 文件夹有关。这可能是错误的。
到目前为止,我发现的几乎所有教程/建议/文章都指向我使用这种方法
getServletContext().getRealPath()
这在我的情况下似乎不起作用
任何帮助将不胜感激。
唐
【问题讨论】: