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

sax java.io.FileNotFoundException

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a class "xml_to_java". It is supposed to print out all the elements of "java_exam.xml". It is invoked from a servlet "trans_xml_java". I have the xml file in "/WEB-INF/" and both classes are in "WEB-INF/classes" Somehow I get the above io error. The only place where the class finds the xml file is when the xml file is in "jakarta-tomcat/bin". I also copied the file in the root of my application, but it doesn't work. Any idea what I'm doing wrong?
Regards,
Francois.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With tomcat the default file location is /bin directory, its not a good idea to place the work files under the bin directory - because not all servlet containers can read it.
My idea could be create a directory xmlfiles under web-inf and refer its location in web.xml file

<context-param>
<param-name>xmlfileloc</param-name>
<param-value>/web-inf/xmlfiles</param-value>
<description>Default xml file location</description>
</context-param>

Now in ur servlet try to get this parameters with the following code
String xmlfileloc = getServletContext().getInitParameter("xmlfileloc");
 
Francois Bourgault
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Balaji,
Sorry about the late reply. What you mention still doesn't work. Even if I hardcode the path, tomcat can't find the file. Here's my setup in tomcat:
<webapps>/<my_appl>/source code
<webapps>/<my_appl>/<WEB-INF>/<classes>/*.class
<webapps>/<my_appl>/<xmlfiles>a_xmlfile.xml
I use Tomcat 4.1.18 and I have the following code in xml_to_java.class
xml_nm = "\my_appl\xmlfiles\java_exam.xml";
XMLReader xr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
xr.setContentHandler( this );
xr.parse( new InputSource( new FileReader( xml_nm )) );
This won't work. The only xml file it reads is the one in the bin subdirectory.
What else am I missing in Tomcat setup?
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic