Current popular J2EE web application architecture analysis

zhaozj2021-02-12  149

Architecture overview

The J2EE system includes Java Server Pages (JSP), Java Servlet, Enterprise Bean, Web Service and other technologies. 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:

The various factors are initially determined to form a framework baseline, and the architect designer should screen the technology in the platform (system), the trade-off of various advantages and disadvantages. 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). Two big stages have been experienced in this route:

1.1. Model 1

Model 1 is actually not a stable architecture, even not 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 extensive reference and summarizing 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 MFC, where is the picture:

1.3. Multi-layer application

The figure below 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. Candidate

Currently, the framework of realizing 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. Struts and MVC

The purpose of the model 2 is the same as the purpose of the MVC, so the model 2 can be substantially equal to MVC. The figure below reflects the operation mechanism of Struts:

2.1.1.1. Control

As shown, its main components are 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

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

Form Beans It 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 implement 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. Detail analysis of Struts

2.1.2.1. View - Control - Model

The user issued a * .do's HTTP request. After the control component receives this request, find the action map for this request, check if the corresponding action object (Action instance) is created, 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.

Below is a code instance of logon.jsp:

<% @ page language = "java"%> <% @ Taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%> <% @ Taglib URI = "/ Web-INF / STRUTS- HTML.TLD "prefix =" html "%> <bean: message key =" logon.title "/> </ title> <html: base /> </ head> <body bgcolor = "white"> <html: errors /> <! - If an error will appear here -> <html: form action = "/ logon" FOCUS = "Username"> <table Border = "0" width = "100%"> <TR> <trh align = "right"> <bean: message key = "prompt.username" /> </ th> <TD align = "left"> <html : Text property = "username" size = "16" maxlength = "16" /> <TD> </ tr> <tr> <trh align = "right"> <bean: message key = "prompt.password" / > </ th> <td align = "left"> <html: password property = "password" size = "16" maxlength = "16" redisplay = "false" /> </ td> </ tr> <TR> <TD align = "right"> <html: Submit property = "submit" value = "submit" /> </ td> <TD align = "left"> <html: reset /> </ td> </ tr> </ TABLE> 2.1.2.2. Model to View</p> <p>Modeling to the view refers to the process of loading system data to the view before display. System data is typically information on Java Bean in the model. The schematic representation of the HTML: Form custom label for the JSP of the control component Forward.</p> <p>HTML: Form custom label Processing Objects From Application Scope (Implemented by Querying the properties of the ServletContext object) Get the action mapping of the previously by the control component ActionServlet where the action mapping, by HTML: Form, the Actionform name, type, and range Waiting for information, find an actionform in the corresponding range, if there is, use its information to populate the HTML Form form [The actual fill action in the nesting HTML: Text, etc.]. Otherwise create an ActionForm object within the respective range. 2.1.3. Excellent</p> <p>advantage:</p> <p>Some developers began adopting and promoting this framework as an open source project, there were many advanced implementation of ideas for large-scale application support. Navigation definition</p> <p>Disadvantages:</p> <p>It is not a Taglib that is not complex enough for the development tool. It takes a long time to master HTML Form and ActionForm's matching, but this is also its essence.</p> <p>Modify It is recommended to modify the ActionForm properties to modify the method of reading or generating an XML document, then use the XML document with an XML document with an XML document, and adapt to the application of the data structure.</p> <p>2.2. Jato</p> <p>The JATO application framework is the old name of the IPlanet application framework. It is a mature, powerful, J2EE-based application framework for developing web applications. Combined with display fields, application events, components hierarchy, and with page-centric development methods, as well as concepts such as MVC and service to worker service-to-workers. Jato can be applied to medium, large, large-scale web applications. But it is not an enterprise-level application framework, that is, it does not directly provide a method of creating EJB, Web Services, etc., but it can construct a customer application access to the corporate layer component.</p> <p>This framework function has three components:</p> <p>Iplanet Application Framework; iPlanet Application Framework Component; IPlanet Application Frame Extension.</p> <p>The application framework core defines the minimum core of the basic interface, object protocol, simple component, and IPlanet application framework. Includes view simple components, model simple components, request distribution components, and reusable command objects. IPLANET Application Frame Components With the basic interfaces, protocols, and components defined by the framework, protocols and components provide high-level reuse components that are both high-level components that are unrelated to a particular visual effect, and they also provide specific utility environments, improve availability. Vertical components. The frame extension implements a method of accessing a non-J2EE environment with a framework. Typically, the extension is used to seamless access to the J2EE container specific feature. The JATO platform stack map clearly expresses this situation.</p> <p>Jato's largest power is: For rapid development users, you can use framework components and extended productivity. For users who require greater flexibility, you can implement interface-supplied interfaces to hold the framework compatibility of the application.</p> <p>This figure represents a JATO application that simply implements the control component module1servlet, view component ListCustomersModuleImpl, and a listCustomers.jsp file that displays the client agent display interface. And clearly indicate the inheritance relationship between these components and the JATO frame assembly.</p> <p>The JATO tag library provides the interface of the View object with the JSP file. The label handler in the library is responsible for implementing the information synchronization and exchange of the VIEW object and JSP generated client documentation. This figure clearly expresses this corresponding relationship.</p> <p>2.2.1. MVC analysis</p> <p>The front-end control component receives any request sent by the user, this can specify the request distribution component in web.xml to be responsible for view management and navigation, and the front-end control component package is implemented together in ApplicationServletBase. Application developers need to implement one such inheritance for each subsystem (Human Resources, Finance, CRM, etc.). Request a distribution component distribution request to workers, workers have implemented Command interfaces. Applying developers can implement this interface. JATO provides a default implementation: DefaultRequestHandingCommand, which will transmit the request to the specific event of the view component.</p> <p>The combined view refers to the hierarchical relationship that the view component is displayed to the user: the root view is an object field of a ViewBean class is an object of a DisplayField class. The container view is an object of a ContainerView class. The hierarchical relationship between the view component class is shown below:</p> <p>2.2.2. Advantages and Disadvantages</p> <p>advantage:</p> <p>This framework has a large adaptation range, which provides the underlying interface, and an immediate assembly that has an immediate development concept of the client RAD development tool, such as a page as a page (equivalent to VB), event processing, etc. Support</p> <p>Disadvantages:</p> <p>It is not the business of the current standard, there is no support for the development tool (JATO has been prepared for the tool support), and the developer has specified the specific navigation URL in the view in the view.</p> <p>Modifying suggests a number of View / Model modifications to XML documents to pass data, plus the concentrated web navigation definition</p> <p>2.3. JSF (JavaServer Faces)</p> <p>JSF is a framework for developing a web application user interface, including Sun, JSF technology including:</p> <p>A set of APIs, it implements the UI component, the status of the management component, the process, input check, definition page navigation, support internationalization and access; an JSP custom label library implements the interface with JSP.</p> <p>JSF is very simple and is a defined programming model. With this technique, developers are connected to the data source of these components and applications by combining the available UI components in the page, and the events generated by the client to the server-side event processor are programmed. JSP handles complex work after all the scenes, so that developers focus on application code.</p> <p>2.3.1. Struts, Jato and JSF comparison</p> <p>Some of them overlap, but the focus is different.</p> <p>Both Struts and Jato provide an MVC application model, while JSF only provides programming interfaces on the user interface. This means that the previously involved range is wide than the latter. The JSF can be part of the top two in the UI development. The release version of JSF's specification will be released at the end of 2002, and it may be better than this time. In addition, there will be tools to support the application development of this framework.</p> <p>2.4. WAF</p> <p>WAF is a referusion of Web Application Framwork, which is the application framework proposed in the Sun Blue Book Example. It implements MVC and other good design patterns.</p> <p>2.4.1. Details analysis</p> <p>Click here to see the big picture</p> <p>2.4.2. View - Control - Model</p> <p>As shown, the two XML configuration files written by developers define the operational parameters of WAF. ScreenDefinition.xml defines a series of screens. Mapping.xml defines the screen that should be displayed after an action, but does not specify the screen to get the data.</p> <p>The user issues an HTTP request (* .screen), received by the TemplateServlet screen control component, it extracts the request information, set the request object CurrentScreen property, and send the request to the template JSP. After the template JSP receives the request, the Template tab in the JSP looks at this current screen and gets the specific parameters of this screen from the screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file (screen definition file) Assuming that the HTML form is included in the HTML to the customer, the user is submitted after entering certain data, issuing an HTTP request (* .do). This request is received by MainServlet, which extracts request information, checks the action mapping file (mapping.xml), and sets the action object (HttPaction object) that processes this request, handed over to the RequestProsessor object processing. The REQUESTPROSESSOR object calls an action object Complete a task, and if you need further processing, the RequestProsessor object calls the event handling mechanism for the WebClientController object. After processing the request, the mainservlet is obtained from the screen stream management object and passes the request to the JSP file of this screen.</p> <p>It is worth mentioning that the WebClientControl Event Processing mechanism finally transmits the data of the HTTP request to the EJBAction object. Thus, the HTTPAction object and the EJBAction object form two-level processing mechanism, the previous level is closely correlated with the request object, and the data package is encapsulated to form an EVENT object, and then transmitted to the EJBAction object, the latter is independent of the request object. This approach can form a session level data processing mechanism. The following figure shows this method. HTTPAction1 object processes a request and puts the data in a status sessionbean. HttPAction2 is also the case. After the HTTPAction3 receives the HTTP request, the control is transmitted to the EJBAction, the latter acquisition status sessionBean data, processing the request, successfully clear control status SessionBean Content. This mechanism is ideally adapted to multiple input pages to meet the input data of a business (such as shopping cart).</p> <p>2.4.3. Advantages and Disadvantages</p> <p>advantage</p> <p>Screen navigation definitions are clearly provided for the extension of the framework.</p> <p>Disadvantage</p> <p>The source code is more chaotic, stability and reliability no one verifies. Just a frame torso, there is no official MODEL layer, the concept of the view is not strong, no model to the definition of the view</p> <p>The modified opinion has only one frame torso, providing flexibility in achieving its own application framework. Without a rigid view concept, it provides an expansion interface that is input to the model on the web, such as inserting XML data exchange.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-6521.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="6521" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.043</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'SFqGDpd44J6Gv7KCxcZh_2FWE3IdvYphEIm2YMpJbznbpMNQDn8JnrFyFPbhIhILgDiu9odd1BiOqD2TAPcTZEjA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>