• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

getPathtranslated() returned null in tomcat 8 after dispather call

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I run same below program in tomcat 7 and tomcat 8 then I got null value in tomcat 8 but I got full translated path in tomcat 7.0.

http://localhost:8080/TestApp/request_info_example/apple+orange?param=zzz

web.xml entry
<servlet>
<servlet-name>TomcatRequestInfoExample</servlet-name>
<servlet-class>mypkg.RequestInfoExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TomcatRequestInfoExample</servlet-name>
<url-pattern>/request_info_example/*</url-pattern>
</servlet-mapping>

RequestInfoExample

String pathTraslated = request.getPathTranslated(); // Tomcat 8 returns D:\Tomcat-8.0.30\webapps\TestApp\apple+orange and tomcat 7 returns D:\Tomcat-7\webapps\TestApp\apple+orange
request.getRequestDispatcher("/home.jsp").forward(request, response);

but in home.jsp page

<%=request.getPathTranslated() %> //// Tomcat 8 returns null and tomcat 7 returns D:\Tomcat-7\webapps\TestApp\apple+orange

how to get request.getPathTranslated() value in tomcat 8 after Dispatcher call ?

I want to get result in home.jsp page same as tomcat 7 in tomcat 8 version.

it seems CGI PATH_TRANSLATED value is not getting in tomcat 8 if we call getRequestDispatcher().

Please help if someone know this in details and let me know what I have to do in tomcat 8 to achieve value same as tomcat 6 or 7.


 
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
RajnishKushwaha Kushwaha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
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.
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic