Jsp for the business layer

Why shouldn't we use JSP for the business layer?

Is this performance? Or is it just good practice? Of course, reusablity is one of the reasons. Also, is there a killer reason why we should use jsp for the business layer?

+1
jsp
Dec 02 '09 at 7:40
source share
4 answers

A few reasons:

  • Repeatability: you cannot reuse scripts.
  • Interchangeability: You cannot create abstract scripts.
  • OO ability: you cannot use inheritance / composition.
  • Debugging: if the scriptlet throws an exception halfway, all you get is a blank page.
  • Verification: scripts are not checked per unit.
  • Maintaining Health: Saldo takes more time to maintain mixed / cluttered code logic.

There are more, but it comes down to the fact that scriptlets are bad practice .

You can do quite a lot at presentation level with JSTL and EL . If you get to the point that this is not possible with any of them, and you are forced to grab scripts, then the code logic ultimately belongs to the real Java class. You can use the Servlet class to manage requests / preprocess / postprocess, you can use Filter to filter requests, you can use the DAO class to interact with the database, you can use the Javabean class to store / transfer / access data, you can use the class Domain for business logic, you can use the Utility class for static tools.

+8
Dec 02 '09 at 11:24
source share

A common reason is the separation of problems. You must simplify the presentation change without affecting the business layer.

+1
Dec 02 '09 at 7:42
source share

Repeatability and maintainability - this is one of the huge problems.

Consider the following situation:

  • Imagine that you want to create an iPhone version of the application, you have to transfer all the business logic to the iPhone, now it allows you to have the Eclipse RCP interface for the application and Flash; then integrate with the python based system.

  • Since business logic and presentation are in the same file, a creative web developer should find out if Java is going to create a better interface without hacking the application.

0
Dec 02 '09 at 7:54
source share

If you create an application that is larger than 5 pages, mixing logic and presentation can make your life more difficult. But here is my unpopular opinion - for small applications (or even medium ones) with one developer who "knows his code", it is quite normal to use JSP for business logic. It can be jsps placed in the /action/ folder, which is later redirected to presentation ones, or it can be the same jsps where the request comes from. I have an example for this - at the beginning of my development practice, I created a network strategy game based almost exclusively on jsps self-service. That was 5 years ago. A few weeks ago, I looked at my code base, and I could understand everything. Therefore, if you are just starting out, and do not want to start with a large structure that will make your learning curve even steeper, and you do not expect your project to be very large or become commercial (sidenote: mine became commercial at some point) then feel free to use jsps for business logic, but keep in mind that this is not good practice in the general case.

0
Dec 02 '09 at 8:07
source share



All Articles