• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading XML in JSP

 
Nikki Agr
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already use JSTL in your JSP pages, there are also tags libraries which could leverage your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic