Struts notes

xiaoxiao2021-03-06  43

Struts implements MVC mechanism: Struts is essentially an MVC framework implemented on the basis of JSP Model2. Where the model consists of a JavaBean or EJB component that implements business logic, the controller is implemented by the ActionServlet and Action, and the view consists of a set of JSP files.

The view is a set of JSP files, no business logic and model information, only standard JSP tags or custom tags (usually in the view module); model represents the status and business logic of the application, usually by JavaBean or EJB composition; the controller is implemented by the ActionServlet class and the Action class. ActionServlet plays the role of the central controller in the MVC model, forwarding the customer request to the action object, Action is responsible for calling the model, updating the status of the model, and helps control application Process process ...

Struts workflow: For web applications with the Struts framework, load and initialize the ActionServlet when the web application is started, and the ActionServlet reads configuration information from Struts-Config.xml, and stores them into various configuration objects, for example to put an action The mapping information is stored in the ActionMapping object. When the ActionServlet receives the customer request:

1. Retrieve and the user request matching an actionMApping instance, if there is no existence, return to the user request path invalid information;

2. If the ActionForm instance does not exist, create an ActionForm object and save the form content submitted by the customer;

3. Decide whether to call an actionform's validate () method according to the configuration information;

4. If the ActionForm's validate () method returns NULL or returns an ActionerRors object that does not contain an actionMessage, it means that the form is successful;

5.alkServlet Refers to the Action according to the map information included in the actionmapping instance (if the Action instance does not exist, first create an action instance), then call an Excute () method;

6.action's Excute () method Returns an ActionForward object, ActionServlet forwards the client request to the JSP component points to the ActionForward object;

7.alk Forward object points to the JSP component generated a dynamic web page, return to the customer.

For the above flow 4, if one or more Validate () methods returns one or more ActionerRors objects containing an actionMessage, the ActionServlet will directly forward the request to the JSP component that contains the user to submit a form.

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

New Post(0)