In the struts framework, the Actionform object is used to wrap HTML form data and dynamically return data for display to the user, and the custom actionform must conform to the JavaBean specification and inherit the Struts Actionform class. At the same time the user can choose to overwrite two methods: Reset () and validate ().
The only disadvantage of actionform is that for large struts applications, a large number of actionform classes must be created programmatically, and if the HTML form field changes, the associated Actionform class has to be modified and compiled. Struts1.1, the concept of dynamic Actionform class is introduced, and the Dynaactionform class of struts framework and its subclasses implement dynamic Actionform, which is a subclass of the Actionform class. It also provides the function of validator verification framework to implement dynamic verification form (Dynavalidatorform).
1. Configure Dynamic Actionform
Dynamic Actionform supports complete configuration of actionform in the Struts configuration file (Struts-config.xml), and there is no need to write additional programs to create specific actionform classes. The way to configure dynamic Actionform is to configure a <form-bean> element in the struts configuration file to set the Type property to the full name of Dynaactionform or one of its subclasses, for example:
<form-bean name= "Registform" type= "Org.apache.struts.action.DynaActionForm" >
<form-property name= "name" type= "java.lang.String"/>
<form-property name= "PSW1" type= "java.lang.String"/>
<form-property name= "PSW2" type= "java.lang.String"/>
</form-bean>
<form-bean> the <form-property> child element is used to set the dynamic Actionform property,<form-property> The Name property of the element to specify the property name, type to specify the property type, You can set the dynamic Actionform properties to the following Java types: Java.lang.BigDecimal java.lang.BigInteger java.lang.Boolean Java.lang.Byte Java.lang.Character java.lang.Class java.lang.Double java.lang.Float java.lang.Integer Java.lang.Long Java.lang.Short java.lang.String java.sql.Date java.sql.Time java.sql.Timestamp
If the form's field values are Java base types, they should be replaced with the appropriate wrapper type, for example: int type of wrapper type is integer:
<form-property
Initial= "0"
Name= "Age"
Type= "Java.lang.Integer"/>
and set the corresponding dynamic action Form in action:
<action path= "/registsubmit" type= "classmate". Registaction "Name=" Registform "scope=" Request "input="/error.jsp "/>"
2, dynamic Actionform Reset () method reference: Http://www.56boke.com/user1/yhaiz/archives/2006/1910.html
3, access to dynamic Actionform
Both the action class and the JSP have access to dynamic actionform, which is roughly the same as the standard Actionform, with only a small difference, and if a standard Actionform object is used, a get/is provided for each property in the standard Actionform Set method to read or set the property.
Instead, Dynaactionform saves all attributes in a map class object and provides the following common method for accessing all properties:
Public Object Get (String name);
public void Set (String name,object value);
The Get (string name) method returns the property value based on the specified property name, and the set (string Name,object value) method is used to assign a value to the given property. For example, if you access the email attribute in the Dynaactionform class, you can use:
Get email
string email = (string) form.get ("email");
Set Email
Form.set ("email", example@example.com);
This creates the action Bean to receive the form data from the dynamic Actionform:
public class Registaction extends Action {
Public Actionforward Execute (actionmapping mapping, actionform form, httpservletrequest request, HttpServletResponse Response) throws Exception {
Dynaactionform dyform = (dynaactionform) Form;
Get Dynamic Action Form
String name = (string) dyform.get ("name");
String PSW1 = (string) dyform.get ("PSW1");
String psw2 = (string) dyform.get ("PSW2"); .......................................................
On the JSP page, as with Actionform: <form action= "registsubmit.do" method= "POST" >