Analysis of the current popular Java EE Web application architecture (I.)

Source: Internet
Author: User
Tags html form http post

  • Architecture Overview
  • The EE system includes Java Server Pages (JSP), Java SERVLET, Enterprise Bean,web Service and other technologies. The advent of these technologies provides a very competitive option for the development of Web applications in the e-commerce era. How to combine these technologies to form a stable architecture that adapts to 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 form an architectural baseline, the architect wants to sift through the technologies in the platform (System) and weigh the pros and cons. Often the architect should read a large amount of technical material in the process, listen to the project team members, consider the needs of the field experts, consider the cost of sponsors (including development costs and operating maintenance costs) limit. Once the architectural design has been reviewed, these factors initially have the role of the project in the overall process of positioning.

    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 largely determined. Many project managers are concerned about the technical skills of the team members, who need training to provide training, but the project manager simply does not have a clear technical training requirement for the technology ocean the architect faces. How can we not train all the technology in the system? With the architectural milestones baseline, the project manager can determine what technology will be used in the development of the project, which is the most accurate to suggest that training needs should be. However, in actual project development, technical training can be performed concurrently with the architecture design before the baseline is determined.

    Division of roles

    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, enabling project team members to position their tasks well. A good architectural blueprint can also standardize tasks, which can be well divided into categories, with the same or similar workload and nature of tasks in the same class. This is a very good basis for estimating the workload.

    Operation and Maintenance

    Previously said that each task in the frame composition has a better positioning. Anyone can use it to quickly familiarize themselves with the entire project and to locate the error point more quickly when errors occur. In addition, with a clear architecture diagram, the project version management also has a good version of the tree trunk.

    Scalability

    Architecture is like a towering tree trunk, as long as the trunk root, trunk thick, long some offshoot, add some leaves easy undoubtedly. Similarly, there is a stable and proven architecture that adds one or two business components that are very fast and easy.

    Everyone knows these benefits and is bent on forming a Java EE application architecture (like MFC in the Windows platform). There are two major stages in this journey:

    1.1. Model 1

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

    In general, the benefits of this model are simple, but it mixes business logic with performance, which is not tolerable for large applications.

    1.2. Model 2

    After some practice and extensive experience and lessons learned, the Java EE application finally ushered in the MVC (model-View-control) model. MVC pattern is not the Java EE Industry People unconventional, so I talked about GF. The core of MVC is the loose coupling of three layers or even multiple layers. This is a boon and a lifesaver for component-based, technology-expanding Java EE systems.

    It inserts a control component between the browser (this document is called a browser by the client Agent) and the JSP or servlet. This control component centralizes the distribution logic that handles HTTP requests sent by the browser, meaning that it distributes the request to the appropriate web-tier JSP or servlet based on the URL of the HTTP request, the input parameters, and the internal state of the current application. It is also responsible for selecting the next view (in the Java EE, Jsp,servlet will generate the HTML back to the browser to form a view). Centralized control components also facilitate security validation, logging, and sometimes encapsulating request data to the following Web tier layer. This set of logical implementations forms an application framework like MFC, where

    1.3. Multi-layer applications

    It is a typical multi-layer application model in the Java EE system.

    Client tier Customer Tiers

    Typically a browser or other application. The client layer generally supports the HTTP protocol, also known as the Client Agent.

    Web tier Web application tier

    In Java EE, this layer is run by the Web container, which includes Web Parts such as JSPs, Servlets, 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 the traditional information system such as finance, CRM, etc., which is characterized by database system support.

    The application framework is currently focused on the Web layer and is designed to standardize the development of this layer of software. In fact, the enterprise component layer can also implement this model, but currently 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, more efficient.

      1. Candidate Scenarios

    Currently, the framework for implementing Model 2 is also emerging, and the more well-known frameworks are listed below.

    2.1. Apache Struts

    Struts is a free open source Web layer application framework, Apache software fund dedicated to struts development. Struts are highly configurable, and have a growing list of features. A front-end control component, a series of action classes, action maps, utility classes that handle XML, server-side Java Bean autofill, Web Forms that support validation, internationalization support, HTML generation, implementation of performance logic and templates make up 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. Embodies the operation mechanism of struts:

    2.1.1.1. Control

    , its main component is a general-purpose 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 classes (which are subclasses of the action Class). In addition, 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, which 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

    Designed 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 a JSP tag library: Html,bean,logic,template and so on to achieve this goal, and is conducive to separate performance logic and program logic.

    2.1.2. Struts Detail Analysis

    2.1.2.1. View-Control-model

    The user issues a *.do HTTP request, the control component receives the request, finds the action map for the request, checks whether the corresponding Action object (action instance) was created, and if not, calls Actionmapping to generate an action object. The control component saves the action object for later use. The Actionmapping method is then called to get the Actionform object. The actionform is then passed as a parameter to the perform method of the Action object, which is returned to the control component as a Actionforward object after the method is finished. The control component then obtains the path and redirection properties of the next view from this object. If redirection calls Httpservletreponse's method to display the next view, or RequestDispatcher is called sequentially, the ServletContext method continues the HTTP request to the next view.

    When an action object runs the Perform method, an error message may appear. 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 properties of the request object. The action object then calls the GetInput method of the Actionmapping object to get the input parameter from the action map, that is, to generate a view of the inputs, and to generate a Actionforward object with the input parameter returned. The input parameter of the JSP typically has a http:errors custom tag that reads these error messages and displays them on the page.

    2.1.2.2. Model-to-view

    Model-to-view refers to the process by which a view loads system data into a view before it is displayed. System data is generally the information of Java beans within the model. It shows the processing logic of the JSP with Html:form custom tags, which is forward by the control component.

    Html:form custom Label processing objects are obtained from the application scope (by querying the properties of the ServletContext object) to obtain objects previously placed by the control component Actionservlet the action map, by Html:form The Action property searches for Actionform name, type, and range information, finds actionform in the appropriate range, and populates the HTML form form with its information (the actual fill action is in the processing object for custom tags such as nested html:text). Otherwise, a Actionform object is created within the appropriate scope.

    Analysis of the current popular Java EE Web application architecture (I.)

    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.