The getFile() method returns an incorrect path via getServletContext().getRealPath(path), when the servlet isn't running on a root path. This can be reproduced in Tomcat 6.
Here is the fix:
// Get the servlet's real path
String ctxRealPath = getServletContext().getRealPath("/");
// Get the servlet's relative path
String ctxRelativePath = getServletContext().getContextPath();
// Resolved resource path starts with ctx real path
String resolvedPath = ctxRealPath;
// Strip relative path from start of resource path, then append to real path
if (path.startsWith(ctxRelativePath))
resolvedPath += path.substring(ctxRelativePath.length());
else
resolvedPath += path;
return new File(resolvedPath);
Sorry - this issue appears to apply to version 1.2.11 from Maven Central. Not sure what this phantom version is all about, might have missed something!
The getFile() method returns an incorrect path via getServletContext().getRealPath(path), when the servlet isn't running on a root path. This can be reproduced in Tomcat 6.
Here is the fix: