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

Reading a xml file

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to read a xml file located in the same path of my servlet... I�d like to use a relative path to find and open the file...
I�ve tried like this:
--- SimpleServlet.java ---
SAXBuilder b = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
Document configXml = b.build(SimpleServlet.class.getResourceAsStream("/config.xml"));
---
it returned an error:
---
org.jdom.JDOMException: Error on line 0: File "" not found.
---
please help me!
 
Renata fonseca
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ops, sorry...
actually the xml file is located at app dir (the jsp and html file directory)... how can I found the xml file in that directory?
 
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
getServletContext().getRealPath("")
give you actual path example
C:\Tomcat\webapps\urprojectname\
Now its upto you put files according ur needs.
Hope this helps.

Originally posted by Renata fonseca:
ops, sorry...
actually the xml file is located at app dir (the jsp and html file directory)... how can I found the xml file in that directory?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic