Current popular J2EE web application architecture analysis
1. Architecture Overview The J2EE system includes Java Server Pages (JSP), Java Servlet, Enterprise Bean, Web Service, etc. The emergence of these technologies provides a very competitive choice for the development of web applications in the era of e-commerce. How to combine these techniques to form a stable architecture that adapts to the project is a very important step in the project development process. Completing this step can form a main milestone baseline. There are many benefits to forming this baseline: various factors initially determine to form a framework baseline, the architect designer should screen the techniques in the platform (system), and the trade-off of all kinds of pros and cons. Often architect designers should read a lot of technical information in this process, listen to the recommendations of the project team members, consider the needs of the domain experts, consider the sponsors cost (including development costs and operating maintenance costs). Once the architecture is reviewed, these factors have initially have a positioning of the projects in the process of the project. Directional Technical Training Once the architect design has been approved, the technology used by baseline, project development and operation is basically determined. Many project managers are worried about the technical skills of the preparatory project team; they need training sectors, but the project manager will not provide a clear technical training needs on the technology ocean facing the architect. How can you not train all techniques in the system! With architectural milestones, the project manager can determine what technology will be used this project, which is the most accurate training needs. However, in the actual project development, technical training can be designated concurrently with the architecture before the baseline determination. The role is divided into a good architecture blueprint, we can accurately divide work. Such as web design, JSP tag processing class design, servlet design, session bean design, and various implementations. These tasks can be clearly labeled out on the architecture blueprint so that project group members can locate their own tasks well. A good architecture blueprint can also standardize tasks, which can be divided into several categories, which are the same or similar to the task of tasks in the same category. This workload is estimated to have a very good foundation. Operation and maintenance says that each task has a better positioning on the architectural diagram. Anyone can quickly locate the error point when it is quickly familiar with the operation of the entire project. In addition, with a clear architecture map, project version management also has a good version of the tree tors. Scalability architecture is like a trunk of a gorgeous tree, as long as the roots of the torso are tie, the tree is thick, long, plus some leaves, easy to mention. Similarly, there is a stable structure that is actuated, increasing one or two business components are very fast and easy. Everyone knows these benefits and wants to form a such J2EE application architecture (just like MFC in the Windows platform). In this journey, two big phases have been experienced: 1.1. Model 1 Model 1 is actually not a stable architecture, even talking about the formation. The foundation of the model 1 is a JSP file. It extracts parameters from HTTP requests, calls the corresponding business logic, handles HTTP sessions, and finally generate HTTP documents. A series of such JSP files form a complete model 1 application, of course, there may be other auxiliary class or files. Early ASP and PHP technology belong to this situation. In general, the advantage of this model is simple, but it mixes business logic and performance in a piece. This disadvantage is that this disadvantage is tolerant. 1.2. Model 2 After a practice, and widely borrowed and summarized the lessons, J2EE applications finally ushered in MVC (Model-View-Control) mode. The MVC mode is not a newly disciplined J2EE industry, so I talked to Guangfa. The core of the MVC is to do three or even multi-layer loose coupling.
This is a J2EE system that constantly expands based on components, and is really evangelism and savior. It is inserted into a control component between the browser (herein, the customer agent) and JSP or servlets. This control component sets the distribution logic of HTTP requests from the browser, that is, it will send the request to the corresponding Web layer JSP according to the URL of the HTTP request, input parameters, and the internal state of the current application. Servlet. In addition, it is also responsible for choosing the next view (in J2EE, JSP, servlet generates an HTML back to the browser to form a view). Concentrated control components are also conducive to security verification, log records, and sometimes also package request data to the following Web Tier layer. This set of logic has formed an application framework like the MFC, where is shown in Figure: 1.3. Multi-layer application The picture shows a typical multi-layer application model in the J2EE system. The Client Tier client is generally a browser or other application. The client is generally supporting the HTTP protocol, also known as the customer agent. The web tier web application layer is in J2EE, which is run by the web container, which includes web parts such as JSP, Servlet. EJB Tier Enterprise Component Layer Enterprise Component Layer is run by EJB container, supports EJB, JMS, JTA and other services and technology. EIS Tier Enterprise Information System Layer Enterprise Information System includes traditional information systems such as finance, CRM, etc., and is characterized by support for database systems. The application framework is currently focused on the Web layer, which is designed to regulate the development of this layer of software. In fact, enterprise component layers can also achieve this model, but currently exist in the form of design patterns. And some frameworks can be expanded, with the participation of corporate component layer components, the framework will look more compact, more natural, and the efficiency will be higher. 2. Currently, the framework of the model 2 is also emerging, and the more famous framework is listed below. 2.1. Apache Struts Struts is a free open source application framework, Apache Software Fund is committed to the development of Struts. The Struts is highly configurable, and there is a list of growing feature. A front-end control component, a series of action classes, action mappings, processing XML utility classes, server-side Java beans, supported Web forms, international support, generating HTML, realize the performance logic and template composition Struts soul. 2.1.1. The purpose of Struts and MVC model 2 is the same, so the model 2 can be equal to MVC equivalent. The figure below reflects the operation mechanism of Struts: 2.1.1.1. Control is shown in the figure, its main component is a universal control component. This control component provides an entry point that processes all HTTP requests sent to Struts. It intercepts and distributes these requests to the appropriate action classes (these action classes are subclasses of the Action class). In addition, the control assembly is also responsible for populating the from bean with the corresponding request parameters, and transmit it to the action class. Action class implements core business logic, which can access Java Beans or call EJB. The last action class transmits the control right to subsequent JSP files, and the latter generates a view. All of these control logics are configured with a struts-config.xml file. 2.1.1.2. Model model exists in the form of one or several Java Beans. These beans are divided into three: Form Beans, which saves the data from HTTP POST requests, in Struts, all Form Beans are subclasses of the ActionFrom class. Business logic Beans is dedicated to handle business logic. System status Beans It saves session information across multiple HTTP requests, and system status.
2.1.1.3. View Control Components Renew the HTTP request to the JSP file that implements the view. JSP can access Beans and generate results documents feedback to our customers. Struts provides JSP tag libraries: HTML, Bean, Logic, Template, etc. to achieve this, and facilitate separate performance logic and program logic. 2.1.2. Struts Details Analysis 2.1.2.1. View - Control - Model Users issued a * .do's HTTP request, after receiving this request, find the action map for this request, and then check if it has created the corresponding Action object (Action instance), if not, call ActionMApping to generate an action object, the control component saves this action object for later use. The method of calling an actionMApping is called to get an ActionForm object. The ActionForm is then transmitted to the Perform method of the action object. This method will return to the control component an ActionForward object. Control components then get the path and redirect properties of the next view from this object. If you call the httpservletReponse method to redirect, the next view is displayed, otherwise, RequestDispatcher, the method of servletContext is successively transmitted to the next view. Error messages may occur when the action object runs the Perform method. The action object can save these error messages into an Error object, then call the SaveErRors method to save this error to the properties of the Request object. Then the action object calls the getInput method of the actionMapping object to obtain the input parameter from the action map, which is generated by the input view, and generates an ActionForward object to the parameter with this INPUT. This INPUT parameter is usually available in the JSP of this INPUT: ErrorS custom tag to read these error messages and displayed on the page.
Here is a logon.jsp code instance: <% @ page language = "java"%> <% @ taglib uri = "/ web-inf / struts-bean.tld" prefix = "bean"%> <% @ taglib URI = "/ Web-inf / struts-html.tld" prefix = "html"%>