Analysis of the current popular Java EE Web application architecture

Source: Internet
Author: User
Tags define object definition end html form http post web services access
j2ee|web| Architecture 1. Schema overview

The Java EE system includes such technologies as the Java-based Server Pages (JSP), the Java SERVLET, the Enterprise Bean,web service, and so on. The advent of these technologies provides a very competitive alternative to the development of Web applications in the E-business era. How to combine these technologies to form a stable framework to meet the needs of the project is a very important step in the project development process. Completing this step can form a major milestone baseline. There are many benefits to forming this baseline:

Preliminary determination of various factors
To create an architectural baseline, architects need to sift through the technology in the Platform (System) and weigh the pros and cons. Often architects in this process have to read a lot of technical information, listen to the suggestions of the team members, consider the needs of the domain experts, consider the sponsor costs (including development costs and operating maintenance costs) limits. Once the architectural design has been reviewed, these factors initially have the role of positioning the project in the overall project process.
Orientation Technology Training
Once the architect-designed architecture has been approved to form a baseline, the technology used to develop and run the project is basically determined. Many project managers are concerned about the technical skills of the members of the project team, who need training to provide training, but the project manager simply does not have a clear technical training requirement for the technical ocean that the architect faces. How can not all the technology in the system training it! With an architectural milestone baseline, the project manager is able to determine what technology will be used in the development of the project, which is to suggest that the training needs should be the most accurate. However, in actual project development, technical training can be performed concurrently with the architecture design prior to baseline determination.
Role Division
With a good architectural blueprint, we can accurately divide the work. such as web design, JSP tag processing class design, SERVLET design, session bean design, there are various implementations. These tasks can be clearly identified in the architectural blueprint, allowing team members to position themselves well. A good architecture blueprint can also standardize tasks, and it can be a good way to classify tasks into categories, with the same or similar workload and nature of tasks in the same class. This workload is estimated to have a very good basis.
Run Maintenance
Previously said each task in the frame composition has a better positioning. Anyone can quickly familiarize themselves with the entire project's operation, and when the error occurs, it can locate the error point more quickly. In addition, with a clear schema diagram, Project versioning also has a good version of the tree torso.
Extensibility
The structure is like a towering big tree's torso, as long as the trunk root is firm, the trunk is thick, grows some offshoot, adds some leaves to be easy undoubtedly. Similarly, there is a stable and time-tested architecture, adding one or two business components is very fast and easy.
Everyone knows these benefits and is bent on forming a Java EE application architecture (like MFC in the Windows platform). It has gone through two major stages of the journey:

1.1. Model 1

Model 1 is not really a stable architecture, not even a framework. The base of Model 1 is the JSP file. It extracts parameters from HTTP requests, invokes the appropriate business logic, processes HTTP sessions, and finally generates HTTP documents. A series of such JSP files form a complete model 1 application, and of course there may be other auxiliary classes or files. This is the case with the early ASP and PHP technologies.

Overall, the benefits of this model are simple, but it mixes business logic with performance, which is intolerable for large applications.

1.2. Model 2

After some practice, and widely learn from and experience lessons, Java-EE application finally ushered in the MVC (model-View-control) mode. The MVC pattern is not a maverick in the Java industry, so I've talked about it in the front. The core of MVC is the loose coupling of three or even multiple layers. This is a boon and a lifesaver for the ever-expanding Java EE system based on component-based, covered technology.

It inserts a control component between the browser (the client agent is called the browser) and the JSP or servlet. This control component concentrates on handling the distribution logic of HTTP requests sent by the browser, that is, it distributes the request to the corresponding web-tier JSP or servlet based on the HTTP request's URL, input parameters, and the current application's internal state. It is also responsible for selecting the next view (in Java EE, Jsp,servlet will generate the HTML back to the browser to form a view). Centralized control components also facilitate security verification, logging, and sometimes encapsulation of request data to the Web tier layer below. The implementation of this set of logic has formed an application framework like MFC, as shown here:

1.3. Multi-layer Application

The following figure is a typical multilayer application model in Java EE system.

Client tier customer Layer
Generally for browsers or other applications. The client layer generally supports the HTTP protocol, also known as the Client Agent.
Web tier Web Application layer
In Java EE, this layer is run by a Web container, which includes a Web Part such as JSP, Servlet, and so on.
EJB Tier Enterprise Component layer
The enterprise component layer is run by the EJB container and supports services and technologies such as EJB, JMS, JTA, and so on.
EIS Tier Enterprise Information System layer
Enterprise Information System includes traditional information system such as finance, CRM and so on, which is characterized by the support of database system.

The application framework is mainly focused on the Web layer, which is designed to standardize the development of this layer of software. In fact, the enterprise component layer can also implement this model, but now mainly in the form of design patterns exist. And some frameworks can be expanded, with the participation of enterprise component layer components, the framework will appear more compact, more natural and more efficient.

2. Candidate programmes

Currently, the framework for implementing Model 2 is also emerging, with a list of more well-known frameworks listed below.

2.1. Apache Struts

Struts is a free open source Web layer application framework, and the Apache Software fund is dedicated to struts development. The Struts tool is highly configurable, and has a list of growing features. A front-end control component, a series of action classes, action mappings, a utility class that handles XML, automatic filling of server-side Java beans, Web Forms that support validation, internationalization support, HTML generation, and the realization of performance logic and templates form the soul of struts.

2.1.1. Struts and MVC

The purpose of Model 2 is the same as that of MVC, so Model 2 can basically be equated with MVC. The following diagram shows the operating mechanism of struts:

2.1.1.1. Control

As shown in the figure, its main component is a common control component. This control component provides an entry point for handling all HTTP requests sent to struts. It intercepts and distributes these requests to the corresponding action class (these action classes are subclasses of the action Class). Additionally, the control component is responsible for populating the from Bean with the corresponding request parameters and passing it to the action class. The action class implements the core business logic that can be accessed by accessing a Java bean or invoking an EJB. The last action class passes control to the subsequent JSP file, which generates the view. All of these control logic is configured using a file called Struts-config.xml.

2.1.1.2. Model

The model exists in the form of one or several Java beans. These beans are divided into three types:

form beans (Form beans)
It holds the data from the HTTP POST request, and in struts, all form beans are subclasses of the Actionfrom class.
Business logic Beans
Specifically used to handle business logic.
System State Beans
It holds session information for a single customer that spans multiple HTTP requests, as well as the system state.
2.1.1.3. View

The control component continues to transmit HTTP requests to the JSP file that implements the view. The JSP can access the beans and generate the resulting document feedback to the customer. Struts provides JSP tag libraries: Html,bean,logic,template To achieve this goal, and facilitates the separation of presentation logic and procedural logic.

Detail analysis of 2.1.2 Struts

2.1.2.1. View-Control-model

The user emits a *.do HTTP request, the control component receives the request, looks for the action mapping for the request, checks whether the corresponding Action object (action instance) has been created, and if not, calls Actionmapping to generate an action object. The control component saves this action object for later use. Then call the Actionmapping method to get the Actionform object. The actionform is then passed as an argument to the action object's perform method, which is returned to the control component as a Actionforward object. The control component then obtains the path and redirection properties of the next view from this object. If the Httpservletreponse method is invoked to display the next view, the RequestDispatcher is called successively, and the ServletContext method continues to pass the HTTP request to the next view.

You may receive an error message when an Action object runs the Perform method. The action object can save these error messages to an Error object, and then call its own Saveerrors method to save the error to the request object's properties. Then the action object calls the Actionmapping object's GetInput method to get input parameters from the action map, that is, to produce the input view, and to generate a Actionforward object return with this input as the parameter. This input parameter's JSP typically has http:errors custom tags that read these error messages and are displayed on the page.

Here is a logon. Code instance for JSP:

<%@ page language= "java"%>
<%@ taglib uri= "/web-inf/struts-bean.tld" prefix= "Bean"%>
<%@ taglib uri= "/web-inf/struts-html.tld" prefix= "html"%>

<title><bean:message key= "Logon.title"/></title>
<body bgcolor= "White" >


<table border= "0" width= "100%" >

<tr>
<th align= "Right" >
<bean:message key= "Prompt.username"/>
</th>
&LT;TD align= "Left" >
</td>
</tr>

<tr>
<th align= "Right" >
<bean:message key= "Prompt.password"/>
</th>
&LT;TD align= "Left" >
Redisplay= "false"/>
</td>
</tr>

<tr>
&LT;TD align= "Right" >
</td>
&LT;TD align= "Left" >
</td>
</tr>

</table>

2.1.2.2. Model to view

Model to view refers to the process of loading system data into a view before it is displayed. System data is typically information for Java beans in the model. The schematic diagram shows the processing logic of the JSP with Html:form custom tags forward by the control component.

Html:form custom Label processing objects from application scope (implemented by querying the properties of ServletContext objects) to obtain objects such as action mappings previously placed by the control component Actionservlet, by Html:form The action attribute searches for information such as Actionform name, type, and range, and finds actionform in the appropriate range, and if so, populates the HTML form form with its information [the actual padding action is in the processing object of a custom tag such as a nested Html:text]. Otherwise, a Actionform object is created within the corresponding range.

2.1.3. Pros and cons

Advantages:

Some developers have started to adopt and promote this framework
As an open source project, there are many advanced realization ideas
Good support for large applications
A centralized web navigation definition
Disadvantages:

Not an industry standard
Insufficient support for development tools
Complex taglib, it takes a long time to master
The combination of HTML form and Actionform is closed, but it is also the essence of it.
Modify recommendations
Modify the Actionform property's settings and accessors to read or generate XML documents, and then exchange the data between HTML form and Actionform with XML documents, so that it is loosely coupled to adapt to the application of the data structure easily changing.

2.2. Jato

The Jato application framework is the old name of the iplanet application framework. It is a mature and powerful application framework for developing Web applications based on the Java EE standard. Combines concepts such as display fields, application events, component hierarchies, and page-centric development methods, and design patterns for MVC and services to worker service-to-workers. Jato can be applied to medium, large and Super scale Web applications. But it is also not an application framework for the enterprise layer, which means that it does not directly provide a way to create enterprise-tier components such as EJB, WEB services, but it can be used to construct client applications that access enterprise-tier components.

This framework features three main components:

iplanet application Framework Core;
iplanet application framework components;
iplanet application Framework extension.
The core of the application framework defines the basic interfaces, object protocols, simple components, and the smallest core of the Iplanet application framework program. Includes view simple components, model simple components, request distribution components, and reusable command objects. The Iplanet application framework component leverages the basic interfaces, protocols, and components defined by the framework core to provide developers with high-level reusable components that have a horizontal component unrelated to a particular visual effect, as well as vertical components that are specifically provided to suit a particular practical environment and increase availability. Framework extension implements a framework-compatible approach to non-Java environment. Typically, extensions are used by framework applications to seamlessly access the Java container-specific functionality. The Jato platform stack diagram clearly expresses the situation.

Jato's greatest power: for fast-developing users, you can leverage framework components and extensions to increase productivity, and for users who require greater flexibility, you can implement the interface provided by the framework core to maintain application framework compatibility.

This diagram represents the implementation of a JATO application that can simply implement control component Module1servlet, view component Listcustomersviewbean and model component Customersmoduleimpl, And a listcustomers.jsp file that shows the interface to the client agent. It is also clear that these components are inherited from the Jato framework component.

The Jato Tag library provides an interface between the View object and the JSP file. The label handler in the library is responsible for synchronizing and exchanging information between the View object and the client document generated by the JSP. This diagram clearly expresses this correspondence.

2.2.1. MVC Analysis

The front-end control component receives any requests from the user, which specifies that the request distribution component is responsible for view management and navigation in Web.xml, and that the front-end control component is encapsulated in Applicationservletbase. Application developers need to implement one such inheritance for each subsystem (human resources, finance, CRM, etc.).

Request distribution component distribution request to worker, worker implements command interface. This interface can be implemented by application developers. Jato provides a default implementation: Defaultrequesthandingcommand, which passes the request to a specific event for the view component.

A combination view is the hierarchical relationship that a view component displays to a user: The root view is an object of a Viewbean class, and the container view is an object of a Containerview class. The hierarchical relationships of the view component classes are as follows:

2.2.2. Advantages and Disadvantages Analysis

Advantages:

This framework has a large range of adaptation, which provides the underlying interface, as well as immediately available components
With the client RAD development tools similar to development concepts such as page-centric (equivalent to VB form), event processing, and so on.
Good support for large applications
Disadvantages:

Not an industry standard
There is no support for development tools (although Jato is ready for tool support)
No Web navigation is defined, the developer specifies the specific navigation URL in the view
Modify recommendations
A large number of View/model corresponding to the XML document transfer data, plus a centralized web navigation definition

2.3. JSF (JavaServer Faces)

JSF is a framework for developing a Web application user interface that is being defined by a group of experts, including Sun, and the JSF technologies include:

A set of APIs that implement UI components, manage component status, handle events, input checksums, define page navigation, support internationalization, and access;
A JSP custom tag library implements the interface with the JSP.
JSF is very simple and is a well-defined programming model. With this technology, developers can programmatically program the events from the client to the server-side event handlers by combining the reusable UI components within the page, connecting the components to the application's data source. JSP handles all the complicated work behind the scenes, allowing developers to focus on the application code.

2.3.1. STRUTS, Jato and JSF comparisons

There is a partial overlap between them, but the emphasis is not the same.

Both struts and Jato provide an MVC-style application model, and JSF only provides programming interfaces on the user interface. This means that the former both involve a wider range than the latter. JSF can be the first two parts of the UI development.
The release of the JSF specification will be released at the end of 2002, and the implementation may be later than this time. There will also be tools to support the application development of this framework.
2.4. WAF

WAF is the abbreviation of Web application framwork and is the application framework proposed in the Sun Blue Book Example program. It implements MVC and other good design patterns.

2.4.1. Detail Analysis

Click here to see the big picture

2.4.2. View-Control-model

As shown in the figure, the two XML configuration files written by the developer define the operational parameters of the WAF. Screendefinition.xml defines a series of screens (screen). Mapping.xml defines the screen that should be displayed after an action, but does not specify where the screen will fetch the data.

The user issues an HTTP request (*.screen), which is received by the Templateservlet screen front-end control component, extracts the request information, sets the request object Currentscreen attribute, and then sends requests to the template JSP. Template JSP received the request, the JSP in the template tag to see the current screen, and from the screen definition file (screendefinition.xml) to obtain the specific parameters of the screen, and then generate HTML to return to the customer.

Suppose the HTML returned to the customer includes an HTML form that the user submits after entering some data, issuing an HTTP request (*.do). This request is received by Mainservlet, which extracts the request information, looks at the action mapping file (Mapping.xml), sets the Action object (Httpaction object) to process the request, and gives the Requestprosessor object processing. The Requestprosessor object invokes the action object to complete the task, and if further processing is required, the Requestprosessor object invokes the event handling mechanism of the Webclientcontroler object. After processing the request, Mainservlet gets the next screen from the screen stream management object and passes the request to the JSP file on the screen.

It is worth mentioning that the Webclientcontroler event processing mechanism eventually uploaded the HTTP request data to the Ejbaction object for processing. Thus, the Httpaction object and the Ejbaction object form a two-level processing mechanism, which is closely related to the request object, encapsulates the data to form an event object, and then passes to the Ejbaction object, which is independent of the request object. This approach can form a session-level data processing mechanism. The following illustration shows this method. The HTTPAction1 object processes a request and puts the data in a state Sessionbean, HTTPAction2 also, when HTTPAction3 receives the HTTP request, passes control to Ejbaction, The latter obtains the state Sessionbean data, processes the request, succeeds after the control state Sessionbean the content. This mechanism is very adaptable to multiple input pages to satisfy a business's input data (such as a shopping cart).

2.4.3. Advantages and Disadvantages Analysis

Advantages

The screen navigation definition is clear
Provides a space for the expansion of the framework
Disadvantages

Source of chaos, stability and reliability is no one to verify.
Just a frame torso, no formal model layer, the concept of the view is not strong
No definition of model to view
Revise comments
Only one frame torso is providing flexibility to implement its own application framework. There is no rigid view concept, which provides an extensible interface for inputting Web pages into models, such as inserting XML data exchange.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.