This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes reading XML in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "reading XML in JSP" Watch "reading XML in JSP" New topic
Author

reading XML in JSP

Nikki Agr
Greenhorn

Joined: Nov 09, 2008
Posts: 13
Hi there,
I am trying to read an XML file using the DOM Parser in JSP. The only way it is working for me is when I refer to products.xml by its absolute path.

How do I make it work using its relative path?



Please advise, thanks!
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

you can get the context path , by
(Please check out API, I'm not remembering them now)

and append it the path relative path of .xml file (relative to web app)

Try this,,


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

You really should not be doing this type of processing in a JSP. In any case, it's independent of JSP so I've moved this to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Relative path? Well, that isn't anything to do with XML. That's a question about what the current working directory is in your application server, which appears to be Tomcat. But as I understand it, that's not defined by the servlet specification, so you shouldn't be relying on knowing what it is.

Something like what Sagar suggested should work, though.
Yves Zoundi
Ranch Hand

Joined: Aug 31, 2008
Posts: 47
If you already use JSTL in your JSP pages, there are also tags libraries which could leverage your code.


Author of VFSJFileChooser and XPontus XML Editor
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading XML in JSP