1 Reply Latest reply on Oct 22, 2001 12:18 AM by hstech

    Putting Presentation & Business Logic In JSPs

    1cuervo

      I have developed an application which uses JSPs to provide the presentation layer & EJBs to provide the business logic layer.

      However, I am finding it difficult to maintain all of my EJBs and would find it MUCH simpler if I encapsulated all my logic (both presentation & business logic) in JSPs, thus effectively 'ditching' EJBs in favour of simplicity.

      I appreciate the re-use, security & concurrency advantages of EJB, amongst others, but these are not features critical to my application.

      Do you think my argument is sound? Will JSP/Servlets be able to handle things like Telnet connections & JDBC communications with mySQL? I am sure it will, it's just that I have only ever used JSP/Servlets for creating dynamic web pages.

      Many thanks for your help!

        • 1. Re: Putting Presentation & Business Logic In JSPs
          hstech

          If your question is "will I get away with it?", then the answer really depends on the application. You may get away with it for a very small application that you don't expect to extended over time, but you will likely run into problems with a normal size business application when it comes time to extending or modifying. Either way, it's generally bad to design your application to mix the business and presentation logic.

          If you are dedicated to ditching the EJB-tier, make sure you implement your business logic in a dedicated "logical tier" that is not spread through the presentation logic. You should make good use of Facade classes that prohibit the presentation tier knowing too much about the business logic implementation.

          Another important point to keep in mind is that business logic is normally much more static than presentation logic (that is, it changes a lot less). Try to keep your static and non-static logic as separate as possible. You will find it easier to extend and modify in the future.

          I strongly advise against implementing the above in JSPs (or even in Servlets). Your business logic code should be put into Java classes, and kept very separate to your JSPs and Servlets. This way, if you decide to ever go back to EJBs, then your EJBs simply become wrappers around your business logic classes.

          Hope this helps,
          Aaron.