This week's book giveaway is in the Android forum.
We're giving away four copies of Android Programming: The Big Nerd Ranch Guide and have Bill Phillips & Chris Stewart on-line!
See this thread for details.
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the right file path in Servlet ?  RSS feed

 
chibi riko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my path is :
/WEB-INF/xml-ress/user.xml
 
Stefan Evans
Bartender
Posts: 1835
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of methods on the ServletContext object that can help you load resources from your web application.
- getRealPath turns a web application relative location into a real directory location on the computer
- getResourceAsStream actually loads the file into a stream for you

getResourcesAsStream is slightly more reliable than the getRealPath method
getRealPath might return you a path that can't be used with the standard java.io.File class - e.g. if the servlet container hasn't expanded the war file, it might give you a path including a ! to indicate the file is compressed in an archive.



 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!