Struts 动态Form的验证框架步骤
注:Form有四种:
{
\import org.apache.struts.action.ActionForm;(静态Form)
import org.apache.struts.action.DynaActionForm;(动态Form)
import org.apache.struts.validator.DynaValidatorActionForm;(动态Form'过程'验证,在Validation.xml中应注意的是:<form name="/loginForm"> </form>中name的值应'访问为路径')
()import org.apache.struts.validator.DynaValidatorForm;
}
1
<form-bean name="form1" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String"/>
</form-bean>
注意:这里必须是DynaValidatorForm
2 <action
attribute="loginForm"
input="/login.jsp"
name="form1"
path="/login"
scope="request"
type="action.LoginAction">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
注意:这里name指向form1。另外,保存到内置对象中的是 attribute="loginForm"
3
<form name="loginForm">
<field property="username" depends="minlength">
<arg0 key="loginForm.username"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var><var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>
注意:<form name="loginForm"> 和attribute="loginForm"相对应