Java – JSTL vs JSP Scriptlets

javajspjstl

I want someone to explain some points in BlausC's amazing answer in this question.

He said that scriptlets had some disadvantages, which are:

  1. Reusability: you can't reuse scriptlets. My question : how could I reuse JSTL code?

  2. Replaceability: you can't make scriptlets abstract. What does abstract mean and how could JST become abstract?

  3. OO: you can't make use of inheritance/composition. How could I use OO paradigms in JSTL?

  4. Debugging: if a scriptlet throws an exception halfway, all you get is a blank page.

  5. Testability: scriptlets can't be unit tested. What does that mean, and how can JSTL be unit tested?

  6. Maintainability: per saldo, more time is needed to maintain mingled/cluttered/duplicated code logic. What does this mean?

The last thing is what he quoted form Oracle's recommendation:

JSP scriptlets should not be used for writing business logic.

In the MVC pattern, I use scriptlets only in the presentation layer. What does he mean here?

Best Answer

You seem to concentrate on only the presentation and flow-control part of the scriptlets as in using if, for and switch statements and out.print() things. You seem to compare scriptlets 1:1 with JSTL. This is wrong. I was not talking about the flow control part only (which is indeed to be replaced by JSTL), but about writing raw Java code in JSP files in general. I.e. gathering request parameters, validating and converting values, interacting with database and other Java classes/methods, etc. All things you normally (indirectly) do in a Servlet or Filter.