[ACCEPTED]-Should I be doing JSPX instead of JSP?-jspx

Accepted answer
Score: 55

The main difference is that a JSPX file 9 (officially called a 'JSP document') may 8 be easier to work with because the requirement 7 for well-formed XML may allow your editor 6 to identify more typos and syntax errors 5 as you type.

However, there are also disadvantages. For 4 example, well-formed XML must escape things 3 like less-than signs, so your file could 2 end up with content like:

<script type="text/javascript">
   if (number &lt; 0) {

The XML syntax 1 may also be more verbose.

Score: 23

JSPX has a few inconvenients, on top of 1 my head:

  1. It's hard to generate some kinds of dynamic content; esp. generating an HTML tag with optional attributes (i.e. or depending on a condition). The standard JSP tags which should solve this problem didn't work properly back in the day I started doing JSPX.
  2. No more & nbsp; :-p
  3. You'll really want to put all your Javascript in separate files (or use CDATA sections, etc.). IMHO, you should be using jQuery anyway, so you really don't need to have onclick, etc. attributes...
  4. Tools might not work properly; maybe your IDE does not support anything above plain JSP.
  5. On Tomcat 6.x, at least the versions/config I tried, the generated output does not have any formatting; just a small annoyance, though

On the other hand:

  1. It forces you to write correct XML, which can be manipulated more easily than JSP
  2. Tools might perform instant validation, catching mistakes sooner
  3. Simpler syntax, in my humble opinion
Score: 12

A totally different line of reasoning why 12 you should use jspx instead of jsp:

JSPX 11 and EL makes including javascript and embedded 10 java codes much harder and much less natural 9 to do than jsp. EL is a language specifically 8 tailored for presentation logic.

All this 7 pushes you towards a cleaner separation 6 of UI rendering and other logic. The disadvantage 5 of lots of embedded code within a JSP(X) page 4 is that it's virtually impossible to test 3 easily, whereas practicing this separation 2 of concerns makes most of your logic fully 1 unit-testable.

Score: 6

Hello fellow JDeveloper developer!

I have 12 been working with JSPX pages for over two 11 years and I never had any problems with 10 them being JSPX opposed to JSP. The choice 9 for me to go with JSPX was kinda forced 8 since I use JHeadstart to automatically 7 generate ADF Faces pages and by default, JHeadstart 6 generates everything in JSPX.

JSPX specifies 5 that the document has to be a well-formed 4 XML document. This allows stuff to properly 3 and efficiently parse it. I have heard developers 2 say that this helps your pages be more 'future 1 proof' opposed to JSP.

Score: 6

As stated in Spring 3.1 official documentation 22

"Spring provides a couple of out-of-the-box 21 solutions for JSP and JSTL views."

Also 20 you have to think about the fact that JSPX 19 aims to produce pure XML compliant output. So 18 if your target is HTML5 (which can be XML 17 compliant but increase complexity see my 16 next comments) you got some pain to achieve 15 your goal if you are using Eclipse IDE... If 14 your goal is to produce XHTML then go for 13 JSPX and JDeveloper will support you...

In 12 one of our cie projects we made a POC with 11 both JSP and JSPX and made PROS and CONS 10 and my personal recommandation was to use 9 JSP because we found it much less restrictive 8 and natural to produce HTML5 in a non XML 7 way which is also less restrictive and more 6 compact syntax. We prefer to pick something 5 less restrictive and add "best practices" recommandations 4 like "do not put java scriptlets" inside 3 jsp files. (BTW JSPX also allows you to 2 put scriplets with jsp:scriplet instead 1 of <% ... %>)

Score: 2

@Matthew-
ADF! The application I'm presently 11 working on has 90% of the presentation layer 10 generated by mod PL/SQL. I started working 9 on a few new screens and wanted to investigate 8 other options that might fit into our architecture, without 7 being to much of a learning burden (increasing 6 the complexity of the system/crashing developer's 5 mental models of the system) on fellow developers 4 on the team. So ADF is how I came across 3 JSPX, too.

I saw a "future proof" observation 2 as well...but didn't know how well founded 1 that was.

Score: 2

JSPX is also the recommended view technology 1 in Spring MVC / Spring Web Flow.

Score: 0

Also, another problem I have found with 9 JSPX is when you want to use scriptlets. I 8 agree that clean code is generally good 7 and Java logic in the JSP is generally bad 6 but there are certain instances where you 5 want to use a utility function to return 4 a string value or something where a TagLib 3 or the model (request attributes) would 2 be overkill.

What are everyone's thoughts 1 regarding scriptlets in JSP?

More Related questions