• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Default directory of a web-app  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A jsp page of mine need to parse an xml file. Below is the code snippet



The data.xml is in the same directory of this jsp file. But the jsp couldn't find the xml file and is raising the following exception..

java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 6.0\data.xml (The system cannot find the file specified)



I wonder why this is taking "C:\Program Files\Apache Software Foundation\Tomcat 6.0" as its default directory. Please help me out.

Thanks
Raghav
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have no control over what a servlet container such as Tomcat considers the "current" directory. You should use initialization parameters, a hard coded path or the application context to control the opening of your file.

See for example javax.servlet.ServletContext and the various path related functions there.

Bill
 
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And move that Java code out of a JSP!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!