I had a problem accessing the files in the WebContent folder (in this case, I need to access the WEB-INF folder)
Here I am trying to access the WEB-INF folder.
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()) { } }
I have musicDb.xml ready in the WEB-INF folder, however, when debugging, I always get this path instead
{my local project path}/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/9321A1/WEB-INF/musicDb.xml

I suspect this is because the WebContent folder is not included in the build process. This may be wrong.
Almost every textbook / sentence / article I have found so far points me to this approach using
getServletContext (). GetRealPath ()
which doesn't seem to work in my case
Any help would be appreciated.
Tang
java servlets
Thang do
source share