• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Default directory of a web-app

 
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
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And move that Java code out of a JSP!
 
Don't play dumb with me! But you can try this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic