• Post Reply Bookmark Topic Watch Topic
  • New Topic

relative path to load a resource

 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need to load a file in the init() method of my servlet. The problem is that I do not want to specify an absolute path to the file because I want the servlet to run on multiple AppServers. How would I go about doing this? I have tried this approach:

The templates directory is in the Web-inf/classes directory. The problem is that url is always null, so my file is not being found. There should be a way to do this. Can someone help?
Many thanks,
Barry
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
barry,
Use this
InputStream lo_inputXmlinputStream = getServletContext().getResourceAsStream("/WEB-INF/templates/MyFile.html");
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pradeep! That worked... Appreciate the help

Barry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!