JSPX for XML

Tomcat 5 is actually sucking a lot less than I thought it would. I still need to see its performance, but with built in db-pooling, admin screen and all the neat new features of JSP 2.0, I'm warming up to it.

Last night I was going through the examples - I still don't grok JSP Fragments - and discovered this:

JSPX - XHTML Basic ExampleThis example illustrates how to use JSPX to produce an XHTML basic document suitable for use with mobile phones, televisions, PDAs, vending machines, pagers, car navigation systems, mobile game machines, digital book readers, smart watches, etc.JSPX lets you create dynamic documents in a pure XML syntax compatible with existing XML tools. The XML syntax in JSP 1.2 was awkward and required <jsp:root> to be the root element of the document. This is no longer the case in JSP 2.0.This particular example uses a tag file to produce the DOCTYPE and namespace declarations to make the output of this page a valid XHTML Basic document.

It's very interesting. Like it said, the old JSPX wasn't something I would've ever wnated to play with. I'm pretty sure it was a version of JSP meant for automatic generation, not human readable. But with the .tag file creating the structure the JSPX sets the header and MIME type for you, which is very cool. Because of the way the java code is generated in JSP, if you put the XML header just in plain text, it won't work because Jasper and other JSP parsers will put a newline in front of it, which XML processors don't like. So I've had to work around that by putting something like this on top of all my JSP pages to get "real" XML:

<% out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); %>

I'll have to play with it, but JSPX's might be perfect for producing XHTML pages, exactly as the example said. I need to get something working to see the results in real life...

-Russ

< Previous         Next >