• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP with XML

 
Harry Wordsworth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am trying to brush up on my programming skills and was working my way back through the basic technologies. I am currently trying to read through online tutorials and such to do a very, extremely simple task...to use a JSP file to access an XML file. However I do have some questions in general.

Is using a JSP considered the best way to go about accessing info in an XML document, is javascript the better alternative?
Are theew simple examples somewhere? Am I wasting my time with this JSP & XML experiment if JSP is not the preferred method for accessing XML?
I am eventually going to brush up on javascript which I have not touched in years and years but thought I would take the path of least resistance.

In otherwords, my java skills and jsp skills I've brushed upon a little already so I thought I would try a simple XML test using a JSP and then later after I have brushed up on javascript, maybe trying the same simple test using javascript.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry Wordsworth wrote:Is using a JSP considered the best way to go about accessing info in an XML document

Debatable. There are the 'x' class of tags in the JSTL which can be used to generate a view using XML data. If you are thinking of putting Java code into the JSP however, that's an obsolete technology from over 15 years ago. No Java code should ever be put into a JSP page.

JSP is a template for an HTML page. Using JSP for anything other than generating view is considered a poor use of the technology.

Rather, if you are going to consume HTML on the server and perform some processing on it, that's the job for a servlet or other Java class; not JSP.

is javascript the better alternative?

You could read the XML file using Ajax, but HTML is a bear to deal with in JavaScript.

I'm still not clear on what your aim is? If it's to learn JSP, consuming XML is not a good choice. If it's to learn how to consume XML, that's another direction.
 
Harry Wordsworth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, thanks for the feedback.

I'm still not clear on what your aim is? If it's to learn JSP, consuming XML is not a good choice. If it's to learn how to consume XML, that's another direction.


Well yeah I guess I was a little confused myself. So my main goal at this point I would say is to try to learn how to consume XML.
So it looks like from your reply that trying to do that by using JSP is not the best way.

So with the languages I know partially, it looks like my best option to try to learn reading/processing XML files are....

Use JSTL with XML
or
use a servlet to read the XML and do any processing and send result to JSP to display. (leaning towards this one)
or
use javascript to read/process the XML




 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry Wordsworth wrote:use a servlet to read the XML and do any processing and send result to JSP to display. (leaning towards this one)

Java has an API to consume XML; a number of them in fact, depending on what your needs are.

use javascript to read/process the XML

I personally avoid this as much as I can.

A JSP only makes sense if you are trying to generate a view, and your needs are simple.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks to me like you're heading in the right direction.

If you want to go from XML --> Java objects, then take a look at JAXB (Java architecture for XML binding)
Basically all you do with that is annotate your POJO with appropriate attributes, and then it can be converted between java and XML relatively easily.
You could then pass those Java objects to a JSP for rendering.


Another standard approach for processing XML is with XSL/XSLT. Which is a whole new world to explore on its own.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!