Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a xml file

 
Renata fonseca
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic