What are the advantages of keeping the business logic outside JSP, since JSP's are meant mainly for presentation? We still see business logic written inside the JSP, so I needed to know what benefit we get by moving business logic out of JSP.
JSP can be easily managed because we can easily separate our business logic with presentation logic. In Servlet technology, we mix our business logic with the presentation logic.
I suggest you to use a MVC patter to add the business logic to your web application on Java classes instead of add the logic into the JSP. Thanks. BTW this is a spring tutorial. With dependency injection and so on yo can simply access the HTTPServlet objects implicitly.
In short, "business logic" is what rules the company has, while "presentation logic" is how the details are shown to users.
4. For larger web applications the best approach is to keep minimal amount of code in each layer and a seperate layer is added centered around the business logic. This layer is termed as a business logic layer. For smaller applications the database objects itself could contain the business logic.
The main benefit of MVC is you can have multiple view and clean and separated architecture & Simplicity
Re usability
Suppose tomorrow you need same app running on a desktop app. then you can just change the view.
Testability
You can unit test your service methods, but you can't simply unit test logic from view.
Maintainability
It is easy to understand the code from Service methods, also we can change it /release service api and maintain it easily
Version ability
You can give version to your API and maintain standard docs related to issues/updates if you use service API instead view for logic
See Also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With