• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get the right file path in Servlet ?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my path is :
/WEB-INF/xml-ress/user.xml
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



reply
    Bookmark Topic Watch Topic
  • New Topic