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

Default directory of a web-app

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.

Author and all-around good cowpoke
Posts: 13078
  • 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.

Posts: 67478
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
    Bookmark Topic Watch Topic
  • New Topic