Today,more and more companies want to develop distributed transactional applications for the enterprise and leverage the speed,security,and reliability of server-side technology. Before presenting a way of designing such a system,several key terms need to be understood.

What is J2EE?

The Java 2 Platform Enterprise Edition (J2EE) technology provides a component-based approach to the design,development,assembly,and deployment of enterprise applications. The J2EE platform provides the ability to reuse components in different applications. J2EE is made up of 13 different technologies including JavaServer Pages,Servlets,Enterprise JavaBeans,JavaMail,XML,JavaMail and many more.

intro_j2ee2.gif

The main technologies that we will be using are:
• JavaServer Pages (JSP).
• Servlets
• EJB

What are JavaServer Pages?

JavaServer Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tags containing Java source code that provide the dynamic content.


What are Servlets?

A Servlet is a Java class that provides special server side service. To display any information on a web page,HTML code is embedded in “println” statements. JSP technology is an extension of Servlets. It is easier to generate GUI pages using JSP because a web page editor (such as Macromedia DreamWeaver ) can be used to create simple pages.

What are Enterprise JavaBeans?

Enterprise JavaBeans (EJB) provides a component specification for the development of scalable and secure middleware components. The EJB Server handles security and transaction management details so developers can focus on implementing the business logic.

What are the benefits of using J2EE?

There are several reasons for using the J2EE set of technologies:

Extensibility and maintainability
Division of work along skill lines
Scalability,portability,availability.
Code reuse.
Interoperability – legacy integration
Focus on implementing business logic
Separation of code with differing rates of change.

Simple J2EE application

In our simple J2EE application,the customer visits a web page (JSP). The request is sent to the web server then passed to the JSP and Servlet engine. The JSP code is executed including a search on the database. The database results are returned to the JSP page. The JSP page dynamically generates a HTML page with the data and sends it to the Customer.

jsp_design_diagrams1.jpg

Advantages.
• Simple of understand and initially develop.

Disadvantages.

• The JSP page is very difficult to maintain. It contains HTML and Java code with queries to the database. The business logic should not be in the JSP; otherwise many pages will need to be changed every time business requirements change.
• Need to have data connectivity code in every JSP page.
• Does not scale up very well.
• Security issues – If a hacker gained access to the web server,all the confidential business logic can be read by opening the JSP files.

The following diagram shows the architecture of a typical J2EE application. This is similar to the previous example,except all business logic is contained in different EJB components.

jsp_design_diagrams_ejb_2.gif

The diagram below shows how the JSP connects to the EJB object,which queries the database. This was the JSP does not contain the database queries and some business logic has been moved into the EJB layer. The EJB container is designed to create copies (instances) of the EJB class as required in memory. This enables it to scale up as multiple requests come in.

jsp_design_diagrams_ejb_components_2b.gif

Advantages.

More secure because all the business logic is stored in the EJB components. An EJB component can be configured so only a specific user in a group can be given access to a limited set of methods.

By adding more EJB Application Servers,the system can easily scale up. However,you need to make sure the EJB components have been designed and deployed correctly.

Transaction Management support – Transaction attributes are specified on an application component during assembly. This lets you group methods into transactions across application components,which means you can easily change application components within a J2EE application and reassign the transaction attributes without changing code and recompiling.

Disadvantages.

All the JSP pages need to include code that locates the EJB components.

There is still quite a bit of functionality in the JSP files.

The current architecture does not support reuse at the JSP level so all the code will need to be replicated. This will cause major maintenance problems.

The JSP pages are still too complex for web designers to use.

Layered Approach.

The actual architecture of the application has been separated out into several layers.

1. Presentation view
2. Presentation logic
3. Business logic
4. Data Model

1. Presentation view.

This is the actual look,feel and presentation of the application. In J2EE,Java Server Pages (JSP) are used to implement your view.

2. Presentation Logic

This is the code required to call business logic and return output to the view. Java Servlets / java beans are the best way to implement presentation logic.

3. Business Logic

This is code required to execute the usecase actions and manipulate the data model. EJB Session beans are the containers of the business logic for all your usecases.

4. Data Model

J2EE provides a useful abstraction for your data model,called EJB Entity beans. These are persistent objects that model your real world business abstractions.

The layered approach has the following benefits:

• Encapsulation – each layer hides details from the other layers. Therefore a layer can change without affecting other layers.
• Separation – Complexity in the system is easier to manage because each layer is focused on a cohesive set of responsibilities.
• Reuse – each layer can provide services to the layer above,so classes can be reused whilst still abstracting the implementation details.

This leads to applications that are more flexible and maintainable.