Struts-HelloApp learning small book

xiaoxiao2021-03-05  33

: An error message generated by other components in the Struts framework.

: Used to create an HTML form, it can associate the field of the HTML form and the properties of the ActionForm bean.

: This tag is a submissions of to create a text box for an HTML form. It is associated with the properties of the Actionform Bean.

: Used to output localized text content, its key property specifies message key, and message key matching text content comes from dedicated Resource bundle

: Used to output the properties of JavaBean. In this example, it is used to output the username property value of the Personbean object:

Tags are used to determine whether JavaBean exists within a specific range, only the contents of the tag body is only executed when JavaBean exists.

The controller component includes an ActionServlet class and an Action class. The ActionServlet class is coming from the Struts frame, which is the control hub of the entire Struts framework, usually does not need to be expanded. The STRUTS framework provides an Action class for extended to handle specific HTTP requests.

When the user submits an HTML form, the Struts framework automatically assembles the form data into the Actionform Bean. The properties in the ActionForm bean are in one or one in the field in the HTML form. The next Struts framework automatically invokes the Validate () method of the Actionform Bean for forms. If the Validate () method returned to the ActionerRors object as null, or does not contain any actionMessage objects, it means no errors, data verification is passed. If the actionMessage object is included in the ActionerRORS, you represent an authentication error, and the Struts framework saves the ActionerRors object to the REQUEST range, then forward the request to the appropriate view component, and the view component via tab puts the request within the REQUEST range The error message contained in the ActionerRORS object is displayed, prompting the user to modify the error. The work mechanism of the Action class: When the ActionForm bean is created, the Struts framework will call the Execute () method of the Action class. The execute () method contains the following parameters:

ActionMapping: Contains this Action configuration information, and corresponds to the element in the struts-config.xml file.

ActionForm: The user's form data is included. When the Struts framework calls the execute () method, the data in the ActionForm has passed form validation.

HTTPSERVLETREQUEST: Current HTTP Request Object

HTTPSERVLETRESPONSE: Current HTTP Response Object

The Execute () method of the Action class returns an ActionForWard object that contains request forwarding path information.

When the HelloAction class calls HTTPSERVLETREQUEST's SetAttribute () method, when you pass the Personbean object to Hello.jsp, you need to provide a property named "Personbean" key: Request.SetAttribute ("Personbean", PB);

Hello.jsp reads the Personbean object by this property key named "Personbean":

Hello !

TYPE = "Hello.HelloAction" // Specify the full class name of the action

Name = "Helloform" // Specify an actionform bean that needs to be passed to Action

Scope = "request" // Specify the range of the ActionForm Bean

Validate = "true" // Specify whether to execute a form verification

INPUT = "/Hello.jsp"> // Specify forwarding path when the table verification fails

// Defines a request forwarding path

The element in this example is configured with the HelloAction component. The corresponding class is Hello.HelloAction, requesting the access path to "HelloWorld", when the Action class is called, the Struts framework should pass the Helloform Bean that already contains form data to it. . Helloform Beans are stored in the Request range and table verification should be performed before calling the Action class. If the form verification fails, the request will be forwarded to the page hello.jsp receiving the user entered, allowing the user to correct errors.

Struts working mechanism