Search code examples
web-servicesjsptomcatweb-applicationstomcat8

getRealPath(“/”)- How does the result of this method differ in Tomcat 7 and Tomcat 8


Using this method

getServletContext().getRealPath("/")

returns '\' at the end when i run my project in Tomcat 7 whereas it is not working as such in Tomcat 8.

For example,

In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"

In Tomcat 8 it returns as "D:\Tomcat\webapps\project"

At present the project is in production so, I am unable to change the code in every part(where i use getRealPath("/")). Is there a way/setting in tomcat level to make it resolved.


Solution

  • This issue has been Fixed in trunk for 9.0.x and in 8.0.x for 8.0.19 onwards.

    For your reference,

    https://bz.apache.org/bugzilla/show_bug.cgi?id=57556