Allowing Relative Paths to Work with Tomcat 8
Please note that in Tomcat 8.0, documents will load using absolute path, and not a relative path.
The relative path is resolved to an absolute in FileContentHandler.setFilePath()
via a call to context.getRealPath(relativePathName)
.
The relativePathName
should start with a /
.
Please see the following code sample to allow relative paths to work on Tomcat 8 (also, see FileContentHandler
in the Content Handler API documentation).
public static void setFilePath(String pathParam, ServletContext context)
{
if ((pathParam.startsWith("./") || pathParam.startsWith(".\\"))
&& context != null)
{
pathParam = pathParam.replace("./", "/"); pathParam = pathParam.replace(".\\\\", "/");
gFilePath = context.getRealPath(pathParam)
+ File.separator;
}
else
{
gFilePath = pathParam;
}
Logger.getInstance().log(Logger.INFO,
"File path for documents is configured to "+ gFilePath);
}
Have questions, corrections, or concerns about this topic? Please let us know!