Actionservlet is a frontcontroller, which is a standard servlet that sends the request to the requestprocessor to handle,
Actionmapping is a subclass of Actionconfig, essentially a mapping of struts-config.xml, from which all configuration information can be obtained
Requestprocessor the corresponding Actionforn and action from actionmapping based on the URL submitted, such as *.do. The request parameters are then mapped to actionform for form validation. If validation passes the Execute () method that invokes the action to execute the action, the Actionfoward is eventually returned.
Actionfoward is a foward wrapper on mapping, corresponding to a URL
Actionform uses the Viewhelper mode, which is an encapsulation of the form in HTML. It contains a validate method for validating the validity of form data. Actionform is a class that conforms to the JavaBean specification, and all properties should satisfy get and set correspondence. For some complex systems, you can also use Dynaactionform to construct a dynamic form, that is, by using prefabricated parameters to generate a form. This allows for a more flexible extension of the program.
Actionerrors is a wrapper over the error message, and once an exception occurs in the execution action or form.validate, a actionerror is generated and eventually added to the actionerrors. In the process of form validation, if an error occurs, the page is redirected to the input page and the error is indicated.
Action is the Requsesthandler used to execute business logic. Only one instance is created for each action. The action is not thread-safe, so you should not access a specific resource in action. In general, you should use the business Delegate mode to access business tier to decouple.
Struts provides a variety of action options to use. A normal action can only perform a task by calling execute, and dispatchaction can perform a variety of tasks, rather than just entering the Execute () function, depending on the configuration parameters. such as Insert,update and so on. Lookupdispatchaction can execute functions based on the name of the Submit Form button. --------------------------------------------------------------------------------------------------------------- -----The Struts Workflow
For Web applications that use the Struts framework, the launch of the Web app will load the init actionservlet,actionservlet from struts- The config file reads configuration information into various configuration objects, such as the map information for the action stored in the Actionmapping object.
When Actionservlet accepts a customer request, the following process is executed.
Process:
(1) The actionmapping instance that the user request matches is reduced and if it does not, returns the information that the user request path is invalid.
(2) If the Actionform instance does not exist, create a Actionform object and save the form data submitted by the customer to the Actionform object.
(3) Determine if form validation is required based on configuration information. If validation is required, call Actionform's Validate () method.
(4) If the Actionform Validate () method returns null or returns a Actionerrors object that does not contain actionmessage, the form validation succeeds.
(5) Actionservlet determines which action to forward the request to, based on the mapping information contained in the Actionmapping instance. If the corresponding action instance does not exist, create the instance first, and then call the action's execute () method.
(6) The Execute () method of the action returns a Actionforward object that actinoservlet the client request to the JSP component that the Actionforward object only wants.
(7) The JSP component that the Actionforward object points to generates a dynamic Web page that is returned to the customer.
For the process of the above process (4), if the Actionform Validate () method returns one or more Actionmessage actionerrors objects, the form validation fails. At this point Actionservlet will forward the request directly to the JSP component that contains the user submission form. In this case, the action object is no longer created and the Execute () method of the action is called.
In the way Struts Mvc/model 2, the controller role is Org.apache.struts.action.ActionServlet, which continues to Javax.servlet.http.HttpServlet, it is common to use Actionservlet directly, and configure the associated group in Web. XML, just as you would configure a generic servlet, you can also configure some initial parameters for Actionservlet use.
In the Mvc/model 2 structure, the ideal pick-up client will not directly request resources or specify the requested JSP page, all customer requests must be sent to the controller, by the controller to determine which object to be transferred to the management, Decide which view page should be displayed and responded to.
(in order to avoid the need for direct JSP pages or related resources, you can put JSP pages or related resources into the WEB application's/web-inf, so that the client can only pass through the controller's forward request resource)
In struts, the controller is Actionservlet, all requests are sent to Actionservlet, for Actionservlet, doget () will adjust Dopost (), So either get or post is the same on the line. Actionservlet Struts-config.xml knows how to allocate objects for requests, including Org.apache.struts.action.ActionMapping, The distribution of objects such as Org.apache.struts.action.ActionForm, Org.apache.struts.action.Action, Struts-config.xml is the focus of the entire struts movement.
Actionservlet will take control of the handle to the action object, and in action you can complete the business request with some model such as Data Transfer object, helper Class, etc., and the Struts uses Jsp/servlet's setattribute () and GetAttribute () methods to communicate with view. The action should return the Actionforward object to Actionservlet, and then actionservlet the forward or include view by the information in the Actionforward, Extract the model information from view and show the results of the deal.
The view section of struts can be a static Web page, a JSP Web page, a struts custom tag, a struts custom tag that can be used in conjunction with some of struts's objects and resources files, and other custom tags, such as Jstl, JSF, and so on.
In struts 1.1 Added Org.apache.struts.action.RequestProcessor category, there are a lot of things that the user asks for the allocation of objects have been handed over to Requestprocessor, the following is the actionservlet after receiving requests for some of the main Action, in the following topics, you will be able to understand the meaning of the struts-config.xml and the way struts works by doing this: |