The getPathTranslated method is treacherous. It's designed to return the absolute filesystem path corresponding to the incoming URL.
But not all URLs correspond to filesystem locations. A webapp server, after all, is not a file server - files are only served in the event that the URL can be translated (based on the rules set in web.xml) to a filesystem location. Which itself is a fallback for when more specific ways of handling the URL have not been defined (for example, servlet resources or JSPs).
Furthermore, if you attempt to reference a static resource, but the webapp is in a WAR archive (that is, still zipped), then none of the resources have absolute filesystem paths, because the normal filesystems cannot access individual members of a ZIP, JAR or WAR file.
In either of the above cases, therefore, the getPathTranslated() method will return null.
For static resources, a better approach is to use the getResource or getResourceAsStream methods.
When it comes to destroying a civilization, gas chambers cannot hold a candle to echo chambers.
posted 3 years ago
Thank you for your interest to reply over on this topic however reply is not helpful as my question is different. this code is running in tomcat 7.0.28 but when I run same code in tomcat 8 then request.getPathTranslated() return null after dispatcher forward.
this line request.getPathTranslated() is being used in 500 files that we can not change in all the files.
I found the solution of this issue. I have created my own java file and inserted in tomcat jar file. Now it's working and no need to change on multiple lines and several codes.
I think I'll just lie down here for a second. And ponder this tiny ad:
how do I do my own kindle-like thing - without amazon