jsp for business layer [closed]

Why shouldn't we use JSP for business layer?

Is it performance? Or is it just a good practise? Ofcourse reusablity is one reason.Other than that is there any killer reason why we should use jsp for business layer?


Several reasons:

  1. Reusability: you can't reuse scriptlets.
  2. Replaceability: you can't make scriptlets abstract.
  3. OO-ability: you can't make use of inheritance/composition.
  4. Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.
  5. Testability: scriptlets are not unit-testable.
  6. Maintainability: per saldo more time is needed to maintain mingled/cluttered code logic.

There are more, but it boils down that scriptlets are a bad practice.

You can do fairly a lot at the presentation layer with JSTL and EL. If you comes to a point that it is not possible with either of them and you're forced to grab scriptlets, then the code logic ultimately belongs in a real Java class. You can use a Servlet class to control/preprocess/postprocess requests, you can use a Filter class to filter requests, you can use a DAO class to do the database interaction, you can use a Javabean class to store/transfer/access data, you can use a Domain class for business logic, you can use an Utility class for static tools.


The usual reason is separation of concerns. You should make it easy to modify the presentation without affecting the business layer.