I am attempting to run a Java web project under Tomcat 8 that traditionally runs under WebSphere. One servlet makes the following call:
xslFilePath = config.getServletContext().getRealPath(System.getProperty("file.separator") + "xsl");
config is an instance of ServletConfig.
The xsl is inside the project and deployed as C:\myproject\build\web\xsl. When the servlet attempts to reference a file located in xslFilePath, I get an exception which indicates that Tomcat is actually looking for the xsl file in C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.3\bin\null. Obviously this is the wrong location, and nothing is found.
Unfortunately I can't change the code because I don't have access to the source. So I would like to know if this is the expected behavior for Tomcat? Is there any Tomcat configuration that will let me ensure the path is referenced to the deployment directory and not to the Tomcat bin directory? Would choosing some other servlet container be preferable? Any advice would be appreciated.
"This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive)." argument to getRealPath () through a .war, getRealPath () will return null. 1. You unpack the .war file manually with jar xf and delete it afterwards. 2.
Java ServletContext.getRealPath - 30 examples found. These are the top rated real world Java examples of javax.servlet.ServletContext.getRealPath extracted from open source projects.
argument to getRealPath () through a .war, getRealPath () will return null. 1. You unpack the .war file manually with jar xf and delete it afterwards. 2. In the Tomcat's config file `server.xml' you change the Host directive's argument from unpackWARs="false" to unpackWARs="true"
Use getRealPath("/xsl").
The parameter for getRealPath() is a 'virtual path' which - unfortunately - is a concept used in the Java docs but not actually defined anywhere. It is assumed to be a path to a resource in your web application and the separator in that case is always '/' regardless of platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With