It's not a secret anymore!
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "reading XML in JSP" Watch "reading XML in JSP" New topic

reading XML in JSP

Nikki Agr

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: 2904

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

Joined: Jan 10, 2002
Posts: 63857

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] [About Bear] [Books by Bear]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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:
subject: reading XML in JSP
It's not a secret anymore!