Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get the real path of a file

 
tianhan digeng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set a virtual path in Tomcat server.xml ,such as <Context path="/demo" doBase="F:\webdemo"
in the F:\webdemo I build a folder "application" ,in the folder I have a file test.jsp ,now I just know the file name is test.jsp,so how to write in a jsp to get the real path of test.jsp
I am a chinese ,so the expression may not right ,please forgive......
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be got in the form of pathOfJsp=request.getContextPath()+"/application/test.jsp"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Narayan.M wrote:It can be got in the form of pathOfJsp=request.getContextPath()+"/application/test.jsp"

The context path is used to form the URL of the resource, and has nothing to do with the file path.

To find the file path of a resource, use the ServletContext.getRealPath() method().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic