• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the right file path in Servlet ?

 
chibi riko
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my path is :
/WEB-INF/xml-ress/user.xml
 
Stefan Evans
Bartender
Posts: 1784
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.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic