tags:

views:

36

answers:

3

Hi, everyone

I want to ask a question about the .jsp. What is the different between using the jsp syntax (e.g. <%! .. %>) and the XML syntax (e.g. <jsp:declaration>...</jsp:declaration>). Is there maintenance or some kind of advs by using one of the syntax? Thank you.

+3  A: 

The original <% %> syntax is somewhat more compact, but if you want tool processable files, it's an advantage to keep everying in XML.

Generally, I'd say that if you're working in XHTML anyway, it's only natural to also use the XML representation of JSP. That way the document, both XHTML and JSP parts, can be validated as XML.

Cumbayah
+1  A: 

The "JSP syntax" allows scriptlets (java code) which is a bad practice.
The JSP are meant to create pure presentation, so no need of heavy java in your page.

When you put Java code in your JSP, it become harder to maintain and reuse, as your page doesn't simply display informations but can interact with your data.

This is why the pure XML syntax is a such great idea. No more java in your JSP, if you need to do some treatments you can use differents taglibs and Expression Language to do simple operations (loops, etc.)


Resources :

On the same topic :

Colin Hebert
It's actually not true that JSPX avoids writing Java code in JSP. It's still possible. Only the wrapping tags are different. [Here](http://stackoverflow.com/questions/3177733/howto-avoid-java-code-in-jsp-files) is by the way a better topic wrt avoiding scriptlets in JSP.
BalusC
+2  A: 

Using XML gives you the advantage that a XML tool can be used to process the JSPX file in one or other way. A XML parser, a XML validator, a XML transformer, a XML marshaller, etc..etc.. That's all.

I have never used JSPX. I have never had the need to have it massaged by some XML tool. Just plain JSP with a HTML5 doctype and no scriptlets. All Java code go in Java classes. Works perfect. For the real MVC works I use Facelets (with JSF). Facelets is less or more the successor of JSP. It's XML based and the major advantage here is that a XML processor can be used to generate HTML output.

BalusC