Actionform, a powerful tool for processing external input

Source: Internet
Author: User

 

Actionform, a powerful tool for processing external input

Actionform is essentially a JavaBean that is used to transmit HTML form data between the view layer and the control layer. The control layer can read user-input form data from the actionform bean, store data from the model layer to the actionform bean, and return the data to the view. It serves as a data bridge.

In struts, to obtain form data, you can use the actionform subclass. The custom actionform must meet the following conditions:

1. inherit from the org. Apache. Struts. Action. actionform class;

2. Define the corresponding public attributes for each HTML input control of the HTTP request;

3. The name of the form Element for data submission on this page must be consistent with the member variable name of the subclass;

4. If you want to verify the data passed to the Controller, you must rewrite it in the subclass.Validate ()Method;

5. If you want to initialize some attributes before filling in actionform, you must implementReset ()Method;

Actionform has two scopes: request and session. If it is set to request, the actionform instance will be saved in the request object. Like other attributes stored in the request, the actionform instance will only be valid within the current request range. If it is set to session, the actionform instance is saved in the session object, and this actionform instance is valid throughout the http session.

Based on different scopes, the Struts framework stores the actionform instance in the request or session object. Therefore, the actionform instance can be retrieved just like any attributes stored in the request or session.

 

Dynamic actionform

Each actionform is a JavaBean, and each form generates the corresponding actionform, which may cause many actionforms. Improved struts1.1 by introducing the dynamic actionform concept. Using the dynaactionform class in the Struts framework and its subclass, You can implement dynamic actionform. You can use the struts configuration file to complete all the configurations of the actionform. You do not need to create a specific actionform class in the application.

Specific configuration method of dynamic actionform: Add a <form-bean> element to <form-beans> In the struts configuration file, and set the type attribute to the full name of dynaactionform or a subclass of it. In the following example, create a dynamic actionform named loginform, which contains two instance variables: username and password:

<Form-beans>

<Form-bean name ="Loginform"Type ="Org. Apache. Struts. Action. dynaactionform">

<Form-peroperty name ="Userid"Type ="Java. Lang. String"/>

<Form-peroperty name ="Userpwd"Type ="Java. Lang. String"/>

</Form-bean>

</Form-beans>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.