For Struts how to control, process the customer request, let us specify the four core components of Struts. These components are: ActionServlet. Action Classes, Action Mapping (here included ActionForward), ActionFrom Bean. Struts ActionServlet controller object ActionServlet inherits from Javax.Servlet.http.httpservlet class, which is the role in Struts Framework is a central controller. It provides a central location to process all of the terminal requests. 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. Follow the Servelt standard, all Servlet must be declared in the web configuration file (web.xml). Similarly, the ActoInServlet must be described in the Web Application Profile (Web.xml), and the configuration information is as follows.
And the Action class typically provides other auxiliary functions, such as Authorization, Logging, and Validation. public ActionForward execute (ActionMapping mapping, ActionForm form, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws java.io.IOException, javax.servlet.ServletException Action is most commonly used is 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 an Execute () method how to be accessed: an Execute () method of the Action instance Note that the customer's own Action subclass must override the Execute () method because the Action class is returned by default. Struts action mapping talked about how a customer request was forwarded and processed by the controller, however, how does the controller know what information forwarded to what kind of Action class? 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
RequestProcessor will then rearrange the form attribute, populate the form with the request, and then call the Validate (...) method of the form object to perform the server-side user input verification. The validate (...) method is called only when the Validate property is set to TRUE only in the ActionMapping object; this is the default behavior. Request.getParameterValues (Parameters) is used to get a string [] object, which is used to form a form fill; the result of the verification should be an ActionerRors object, with org.apache.struts.taglib.html.errostag to display the verification error to the user. ActionForm can also be used to save the current user will be referenced by an intermediate model state that references referenced by a view. When a form object is found by RequestProcessor, it is passed to the Execute (...) method of the request processor. An ActionForm object can also be established by requesting processors. The form object establishment is to provide an intermediate model state to use the request range JSP; which will ensure that the object does not still exist after the validity expires. By default, all forms are saved as sessions. The presence of the form object in the session may result in waste memory, the same, the request processor must track the lifecycle of the form object saved in the session. A good capture form data is to use a separate form bean for related forms across multi-user interactions. Form beans can also be used to store intermediate model states that can be changed by custom tags during feedback. The label usage is avoided in the view, so it is a good task division, the web production group mainly handles the flag, and the application development group mainly handles the Java code. Label factors exit logic accessed the intermediate model status; when accessing nested objects or when this logic can be complex when listed by aggregate. 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.
(9) If the validate () method does not return any errors, the controller transmits ActionForm as the parameter to the Execute () method of the Action instance and execute. 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. Struts' other components Struts framework itself provides a lot of scalable components or Sub Framework, which is convenient for developers 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). 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. The Struts Taglib Struts provides a set of scalable custom tag libraries that simplify 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. For details, please refer to BeanUtils 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). The component of Collectes is mainly provided with some collection or list objects, and the extension is performed on the basis of the original Java Collections Framework. For details, please refer to: http://jakarta.apache.org/commons/collections.html and http://cvs.apache.org/viewcvs/~checkout ~/jakarta-commons/collections/status.html?rev=1.13 Digester This component is translated into Chinese meaning "assembly".