1, solve the problem of too many action
Create an action that inherits from Dispatchaction by Dispatchaction This kind of action allows us to use a parameter in the form, to execute the action in different ways based on the parameters, and to implement the action in a multiple way.
Steps
① set up a inherited from dispatchaction action rule method name
② adds a hidden field value to the form page, assuming Codi value= "insert"
③ set the parameter parameter value to CODI in the action item in the corresponding form in Struts-config.xml
Then when the form is submitted, the Insert () method in the action is executed, changing the way the action is executed by altering the value in the hidden field
2, solve the problem of actionform too much
By means of dynamic actionform, i.e. Dynaactionform
Steps
① in Struts-config.xml
<form-beans>
<form-bean name=”abcForm” type=”org.apache.struts.action.DynaActionForm”>
<form-property name=”userid” type=”java.long.String”></form-property>
</form-bean>
</form-beans>
② in Struts-config.xml
Change the attribute and name in the appropriate action to Abcform
This will be configured with a dynamic actionform
3, solve the problem of dynamic actionform verification
By dynamically validating the actonform, i.e. Dynavalidatorform
Steps
① in Struts-config.xml
The first step with 2, but the type needs to be changed to Org.apache.struts.action.DynaValidatorForm
② Configure a Validation.xml file
<form-validation>
<formset>
<form name="abcForm">
<field property="userid" depends="required">
<arg key="err.userid" resource="true"/>
</field>
</form>
</formset>
</form-validation>
③ configures Err.userid, and errors.required in the Struts resource file
④ Configure the appropriate action in Struts-config.xml, add validate= "true" to add validation support
⑤ Add Struts plugin plugin, set plugin class to Org.apache.struts.validator.ValidatorPlugIn
Add Propertys
Property->pathnames
Value->/web-inf/validator-rules.xml,/web-inf/validation.xml
Such a validation framework is configured!