Struts architecture

zhaozj2021-02-16  51

Struts Framework Architecture (Silver Fox 999) Keywords Struts, Framework, Architecture, ComponenNT, MVC Preparation Knowledge Before starting to learn Struts, the following knowledge points need to be understood: Model - View - Control Software architecture, JSP / servlet Web layer application, J2EE architecture. If you have aware of the customer tag class (Customer Taglib), it is more likely to understand the Taglib of the Struts itself.

Overview This article mainly explains what Struts Framework, its framework structure, component structure, and simple configuration explanation. For its applications, please refer to "Struts Installation and Application" and "Struts Practical Case Analysis" later. The article includes the following four parts: 1. Framework concept and architecture III, Struts concept and architecture, Struts work principle and component (struts Componennts) Struts configuration file profile (Struts Deployment Description)

First, the Framework concept has always said that struts is a web framework. So let me see what is Framework. (I want to translate Framework with the word "frame", but later found less ideal and complete, so I will use Framework's word) Framework concept is not very new, with the development of software development, more In the software development project of the layer, it is reusable, easy to expand, and is a well-tested software component, which is increasingly favored. This means that people can use sufficient time to analyze, build business logic applications, rather than complicated code projects. So people will abstract the solution to the same type of problem, extract into an application framework. This is what we said. Framework's system provides a set of clear mechanisms to make developers easily extend and control the structure of the entire Framework development. Typically, there is a "command and control" component in the framework of Framework ("Command and Control" Component - Framework Factory and Manager. Image (2): Framework system

Basically, based on the application response (Request-response) mode Framework, there is basically composed of the following performance logical structures. (1) Controller - Controlling the coordination of each component in Framework. (2) Business logic - this is the key to Framework wants to solve the problem. Of course, the FRAMWORK itself is just the concept and several basic components of the sufficient service. The real implementation of the customer's business logic, and the developer needs to expand again on Framework. (3) Data logic - Most application systems require data interaction, which mainly includes data logic and data access interfaces. For data logic, if you understand data modeling (data modeling) may be easily understood. Let's go to our topic - Struts' structure

Second, the concept of Struts and the architecture Struts has a group of collaborative classes (components), Servervet, and JSP TAG LIB. The web application based on the Struts architecture basically meets the design criteria for JSP Model2, which can be said to be a change type of MVC design mode. According to the description of Framework on the top, we are easy to understand why Struts is a web framework, not just a combination of tag libraries. But Struts also contains a wealth of tag libraries and utility classes that are independent of the framework. Struts has its own controller, integrating other technologies to realize the model layer (Model) and view layers. In the model layer, Struts can be easily combined with data access technology, including EJB, JDBC, and Object Relation Bridge. At the view layer, Struts can combine with JSP, Velocity Templates, XSL, and so on.

2.1 Struts' relationship with web app

Since Struts is called Web Framework, then it is definitely based primarily based on Web-layer application system development. According to J2EE Architecture, Struts should be the same as the Web Container like JSP / servlet. As shown in the picture (3) (3): Struts and WebApp relationship

2.2 Struts Architecture We say that struts framework is an embodiment of MVC mode. Here we take a look at the architecture of Struts from models, views, and control. Picture (4) shows the principle of the work of the Struts Framework's architecture to respond to customer requests. Picture (4): Struts Architecture

2.2.1 From the view angle (view) is mainly established by JSP, Struts itself includes a set of scalable custom label libraries (Taglib) that simplifies the process of creating user interfaces. Currently include: Bean Tags, HTML Tags, Logic Tags, Nested Tags, TEMPLIB. For more information on them, please refer to the Struts User Manual 2.2.2 From the Model model mainly represents a state of a system (sometimes, the business logic operation of changing the system status is also divided into the model). In Struts, the status of the system is mainly Actiomform Bean, in general, these states are non-persistent. If you need to convert these states into persistent data storage, the Struts itself also provides a utitle package, which can be easily and database operation 2.2.3 From the controller angle (Controller) in Struts Framework, Controller is mainly an ActionServlet, but for business logic The operation is mainly completed by Action, ActionMapping, ActionForward (maybe these components, should be divided into a business logic in the model). Among them, Action plays an implementation of true business logic, and ActionMapping and ActionForward specify the direction of operation of different business logic or processes.

2.3 Struts Basic Components The entire Struts has approximately 15 packs, and nearly 200 classes are composed, and the quantity is still expanding. Here we cannot introduce one by one, only to list several major brief introductions. The following table describes several component packages in the current Struts API, including Action, Actions, Config, Util, Taglib, Validator. The picture (5) shows the relationship between these components. Where Action is the core org.apache.struts.Action of the entire Struts Framework basically, control the core class of the running of the Struts Framework, and the components are in this package, such as the controller ActionServlet we mentioned above. Action, ActionForm, ActionMapping, etc. Struts1.1 is more than 1.0 DynaActionform class. Added Dynamic Extension Generation FormBean Features Org.Apache.Struts.Actions This package is the primary role to provide a specific adapter conversion function between the client's HTTP request and business logic processing, and some of the part of the version 1.0 reproduces the class of frombean, The DynaActionForm component replaced by the ACTION package in Struts1.1 provides mapping of the configuration file struts-config.xml element. This is also a new function in StURTS1.1 org.apache.struts.utilStuts to better support Web Application's application, such as Connection Pool and Message Source. For details, please refer to http://jakarta.apache.org/struts/api/package-summary.htmlorg.Apache.struts.taglib This is not a package, but a customer tag class set. The following includes Bean Tags, HTML Tags, Logic Tags, Nested Tags, Template Tags, for building tag classes for building user interfaces. Org.apache.struts.valiDatorstruts 1.1 Framework adds Validator Framework for dynamic configuration of the FROM form. See http://home.earthlink.net/~dwinterfeldt/

Third, the working principle and components of Struts Framework are controlled for Struts, handle customer requests, let us specifically describe the four core components of Struts. These components are: ActionServlet. Action Classes, Action Mapping (here included ActionForward), ActionFrom Bean. 3.1 Struts ActionServletActionServlet Inherits from Javax.Servlet.http.httpservlets, which plays the role out of control in Struts Framework, see the "Struts System Map" above. The controller ActionServlet is mainly responsible for assembling the HTTP's client request information, forwards to the appropriate processor based on the specified description of the configuration file. (Add the org.apache.struts.Action.Action.RequestProcessor class in Struts 1.1.1, separating the functionality of the process from the controller function. Follow the Servelt standard, all Servlet must be in the web configuration file (web. XML) declaration. Similarly, ActoInServlet must be described in the Web Application Profile (Web.xml), which will be introduced later. When the user submits a request to the server, the actual information is first sent to the controller ActionServlet Once the controller obtains the request, it will pass the request information to some auxiliary classs. These auxiliary classes know how to process the business operations corresponding to the request information. In Struts, this secondary class is Org.apache.struts.Action.action. Usually developers need themselves to inherit the Aciton class to implement their own Action instance.

3.2 Struts Action Classes The role of an Action class, just like a Adaptor between the client request action and the business logic processing, its function is to separate the request with the business logic. Such separation allows the customer request and the ACTION class to have multiple point-to-point mappings. And the Action class typically provides other auxiliary functions, such as Authorization, Logging, and Validation. Action is the most commonly used execute () method. (Note that the previous Perform method is no longer supported in Struts1.1), and there is an Execute () method, please refer to APIDOC, not described herein. When Controller receives a customer request, when the request is transferred to an Action instance, if this instance does not exist, the controller will first create, then call the Execute () method of this Action instance. Struts framework only creates an instance for each Action class in the application system. Because all users use this instance, you must determine your Action class in a multi-threaded environment. The following figure shows how an Execute () method is accessed: image (6): an Execute () method of an Action instance Note that the customer's own Action subclass must override the execute () method, because the Action class is default It is back to NULL. 3.3 Struts action mapping Tell the customer request how to be forwarded and processed by the controller, however, how do the controller know what kind of Action class is forwarded? This requires some mapping configuration instructions corresponding to the action and request information. In Struts, these configuration mapping information is stored in a specific XML file (such as struts-config.xml). These configuration information is read in memory when the system is started, and the Struts Framework is used during operation. In memory, each

Elements correspond to an instance of org.apache.struts.Action.ActionMapping class. The following table shows a login configuration mapping.

The above configuration indicates that when the request information can be submitted via /logonaction.do (where the configured controller map is assumed to be mapped to * .do), the controller entrusts the information to com.test.logonAction. Call the execute () method of the LogonAction instance. At the same time, the mapping instance and the corresponding LogonForm bean information are incorporated. Where Name = LogonForm, the Actionform Bean declared by the form-bean element. The declaration of Form-beans is shown below.

element

Then indicate that the EXECUTE () method of the Action instance is running or, the controller can transfer the response information to the appropriate place according to mapping. As in reality above, if the customer logs in success, call Welcome Forward to return the success information to the /welcome.jsp page. The following instance code can be used to return Welcome Forward at the end of your execute () method. Of course your Welcome Forward must be defined in the Action element properties, as declared above.

Slightly talk about the concept of Global-Forwards. It describes the ActionForward that can be used throughout the application in the configuration file instead of just a specific action. 3.4 Struts ActionForm Bean That told the ActionServlet, Action Classes, and Action Mapping, we mention the concept of Actionform Bean. The non-persistent data store for the message transfer (or state transfer) of an application system is maintained by the Actionform Bean. The main function of ActionForm is the data of the Action to provide data mapped with the client form (if the customer is specified, the data is also verified). Action is responsible for the maintenance of the system data status, and Action is responsible for modifying the data status based on the needs of business logic. After changing the system status, ActionForm automatically returns new data status and keeps. Note: In Struts1.1, the check function of ActionForm is gradually stripped (of course, can still be used). Using Validator Framework for unified management of form data authentication of the entire application system. I believe the information, please refer to: http://home.earthLink.Net/~dwinterfeldt In the use of ActionForm, Struts advocates the value object (Value Object). This makes it possible to understand and use the customer or developers to more clearly understand and use the data status and object state. For each customer request, Struts framework is generally needed to experience the following steps: (1) Check the Action mapping, determine that the ACTIONMM is configured (2) Find Form Bean according to the Name property Configuration Information (3) Check the range of FORMBEAN of the action, determine if there is an instance of this form bean at this range. (4) If there is an instance of this FORM BEAN, it has existed the present request, which is the same type of time, then reuse. (5) Otherwise, re-construct an instance of a FORM BEAN (6) method () method () method for mod (7) Call the corresponding setter method, assigning a status attribute (8) If the validated attribute north is set to true, Then call the FORM BEAN's validate () method. Note: The reset () and validate () methods inherited directly from the ActionFrom class, do not implement what processing, so it is necessary to re-overwate themselves. If the validate () method does not return any errors, the controller transmits the ActionForm as the parameter to the Execute () method of the Action instance and execute.

It is necessary to mention the org.apache.struts.Action.DynaActionform. This is the new feature of Struts1.1. It inherits from Actionform, in the Struts earlier, we must construct a specific ActionFrom subclass, but use DynaActionForm, you can create from Beans based on the attribute set. For more information, please refer to ··· 4, Struts, Struts Framework itself provides a lot of scalable components or sub framework, which is convenient to build a Web layer on its architecture. Such as Upload, Collectes, Logging, and more. Let's take a look at two more important components: ValidationG framework and struts taglib. For other components, please refer to the Struts User Manual (http://jakarta.apache.org/struts/userguide). Some of Stuts1.0 is very good concepts and components, such as Benautils, Collectes, etc., later by the Jakarta Commons project group to absorb Struts Framework. But Struts still needs to rely on these components to work properly. 4.1 Validation Framework for Struts In Struts1.1, the Validation Framework has been added. Increased verification of FORM data submitting. Verify the validate () required for an actionFrom bean is verified by the profile of the Validate (). For more information, please refer to http://home.earthlink.net/~dwinterfeldt. Personal recommendations can adopt this configuration method for small applications, but there is a system with a large Web layer form application in the application system, and the business requirements are relatively large, using the Validation Framework may aggravate the development difficulty, system maintenance difficulty. You can learn from the Validation Framework's JavaScript Validator Tag.

4.2 Struts TaglibStruts provides a set of scalable custom label libraries (Taglib) that simplifies the process of creating user interfaces. Currently include: Bean Tags, HTML Tags, Logic Tags, Nested Tags, TEMPLIB. For the structure and use of Struts Taglib, you can refer to the previous introduction of CUTOMER TAG LIB, please refer to

4.3 BeanUtils's full name of this component is Bean Introspection Utilites. It is a Jakarta Commons project group. Mainly to help build JavaBean properties (Getter, Setter), which already provides a dynamic definition and access to the properties of the bean. For more information, please refer to. Http://jakarta.apache.org/commons/beanutils.html If you are interested in this, you can refer to some information about Java Reflection (Reflectio).

4.4 Collectes This component is mainly provided with some collection or list objects, and extension is performed on the basis of the original Java Collections Framework. For details: http://jakarta.apache.org/commons/collections.html and http://cvs.apache.org/viewcvs/~checkout ~/jakarta-commons/collections/status.html?Rev=1.134 .5 Digester This component is translated into Chinese meaning "assembly". Its main function is some Java class objects of the system based on the XML configuration file. Digester helps you specify the map model between XML and Java objects and allows the customer to customize mapping rules (Rules). For details, please refer to http://jakarta.apache.org/commons/digester.html

4.6 Other related components Due to space issues, there are some components to introduce, including Database Connection Pool, Upload, Logging, Pool, Services. Based on the Struts User Manual, there is a detailed introduction, please refer to.

V. Struts Configuration File Struts Framework specifies (more precisely, it is the controller), allows servletAction, ActionMapping, Action, Actionform these different levels of components interact, coordinated work. As mentioned earlier, these profiles are used in the system when the system is started, and the controller is used for the controller. Struts framework mainly includes three parts of configuration description, one to specify the configuration description of Struts Controller and its related configuration, one for Struts Tag LIB, one is between Struts Components (ActionMapping, Action, Actionform) Relationship between mutual mapping coordination

5.1 For Struts Controller and its related configuration Description Since Struts Controller's primary ActionServlet is inherited from HTTPSERVLET, you must configure an ActionServlet class and its access mapping like configuring a servlet. For more information, please refer to: http://jakarta.apache.org/struts/userguide/building_controller.html#dd_config

5.2 Configuration Description of Struts Tag LIB If your Web Application intends to use Struts Taglib, then you need to configure Struts Taglib in Web.xml. For detailed description and description, please refer to http://jakarta.apache.org/struts/userguide/building_controller.html#dd_config_taglib

5.3 Configuration Description Struts itself has a configuration file in Struts itself, usually Struts-Config.xml. For a description of its DTD document, please refer to http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd (or struts-config_1_0.dtd) General Struts-Config (Version1.1) contains the following Part: (1) Form-bean (2) Global-Forwards (3) Action-mapings (4) Data-Sources For more information, see http://jakarta.apache.org/struts/userguide/building_controller.html#config It is necessary to mention that in Struts1.1, the Multiple Application Support is proposed. In the earliest version of Struts, there is only one struts profile, which is generally struts-config.xml. However, for the development of increasing complex applications, only one place is stored in this file, using and modifying this profile, making it a bottleneck problem for an application. In Struts1.1, you can define multiple profile collaborative work.

Summary Hope that the readers can have a relatively clear understanding of the overall structure of Struts, how to handle the customer request, how to perform business logic processing and automatic circulation can have a conceptual understanding.

The official website of Resource1 Struts: http://jakarta.apache.org/struts/ 2 Struts User Guide http://jakarta.apache.org/struts/userguide3 Article --- Framework Save the dayhttp: // Www.javaworld.com/jw-09-2000/jw-0929-ejbframe.html 4 Article --- Building a java servlet framework using reflectionHttp: //www.javaworld.com/javaworld/jw-11-1999/jw-1 -Servlet.html 5 Validation frameworkHttp: //home.earthLink.net/-/riTerfeldt/http: //cvs.apache.org/viewcvs/jakarta-commons/Validator/6 Article --- Struts1.1, Should i Upgrade? http : //www.theserverside.com/resources/article.jsp? l = struts1_1

转载请注明原文地址:https://www.9cbs.com/read-20646.html

New Post(0)