Chapter 5: Struts Work Flow
Struts PrinciPle and Practice
The above figure is the workflow of Struts. We mentioned before, all requests are submitted to the ActionServlet.
ActionServlet is a FrontController that is a standard servlet, which forwards request to RequestProcessor,
Actionmapping is a subclass of ActionConfig, essentially a map of Struts-Config.xml, which can get all configuration information from it.
RequestProcessor Gets the appropriate actionforn and action from ActionMapping based on the submitted URL, such as * .do. Then correspond to the parameters of the Request to ActionForm, perform Form verification. If verification is called an action () method () method to perform an action, eventually returns ActionFoward.
ActionFoward is a packaging of a foward in mapping, corresponding to a URL
Actionform uses viewhelper mode and is a package for Form in HTML. It includes a validate method for verifying the effectiveness of the FORM data. ActionForm is a class that meets the JavaBean specification, all attributes should meet GET and SET. For some complex systems, DynaActionForm can also be used to construct a dynamic Form, which is generated by a prefabricated parameter. This makes a more flexible extension program.
ActionerRORS is a packaging for error messages, once an exception occurs in execution or form.validate, you can generate an actionerror and eventually add to ActionerRors. During the Form verification, if there is ERROR, the page will be re-directed to the input page, and the error is prompted.
Action is the REQUSESTHANDLER for performing business logic. Each Action only establishes an instance. Action is not a thread safe, so you should not access specific resources in the action. In general, the business delegate mode should be changed to access the business tier to unprepose.
Struts provides a variety of Action for selection. Ordinary Action can only perform a task by calling Execute, and DispatchAction can be performed according to the configuration parameters, not only enter the execute () function, which can perform a variety of tasks. Such as INSERT, UPDATE, etc. The LookUpdispatchaction can perform a function according to the name of the submitting form button.
We can go back to the examples just now, understand the Struts process.
Let's take a look at the EXAMPLE example of Struts:
Chapter 6: Example 2: Login Application Struts PrinciPle And Practice Description: The example 2 is the Struts comes with the example program that implements a large number of Struts Taglibs in the login, registration, and modify the function code, and use the Validator plugin for Form verification but the code Establish a bad example, that is, write a lot of business logic in an action. Part of the code is as follows: Logon.jsp
<% @ page contenttype = "text / html; charset = uTF-8" Language = "java"%>
// Declare taglib <% @ taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
// bean is used to read I18n information from ApplicationResource
hEAD>
// Error message section
// Log in to Form, Action is logion.do
οnsubmit = "Return Validatelogonform (this);"> tH> td> TR> tH> REDISPLAY = "false" /> td> TR> td> td> TR> TABLE> html: form> // Validator plugin for Form verification