Struts实现注册(登陆)的验证过程

 1.首先你要要保证在你的WEB-INF下面要有validation.xml和validator-rules.xml这两个文件,一般情况下在创建web工程的时候validator-rules.xml就会自动生成,所以你必须自己导入文件validation.xml

下面即为该文件
<global>
<constant>
<constant-name>password</constant-name>
<constant-value>^[a-zA-Z]*tiny_mce_markerlt;/constant-value>
</constant>
</global>
<formset>
<constant>
<constant-name>test</constant-name>
<constant-value>6</constant-value>
</constant>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~客户信息验证~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<form name="customForm">
<field
property="customCardID"
depends="required,maxlength">
<arg0 key="custom_CardID"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>18</var-value>
</var>
</field>
<field
property="customTime"
depends="date">
<arg0 key="custom_Time"/>
</field>
<field property="customContact" depends="required">
<arg0 key="custom_Contact"></arg0>
</field>
<field property="customTele" depends="maxlength">
<arg0 key="custom_Tele"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>12</var-value>
</var>
</field>
<field property="customMobile" depends="required,minlength,maxlength">
<arg0 key="custom_Mobile"></arg0>
<arg1 name="minlength" key="${var:minlength}" resource="false"></arg1>
<var>
<var-name>minlength</var-name>
<var-value>10</var-value>
</var>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"></arg1>
<var>
<var-name>maxlength</var-name>
<var-value>13</var-value>
</var>
</field>
<field property="customEmail" depends="email">
<arg0 key="custom_Email"></arg0>
</field>
<field property="customPost" depends="maxlength">
<arg0 key="custom_Post"></arg0>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"></arg1>
<var>
<var-name>maxlength</var-name>
<var-value>6</var-value>
</var>
</field>
<field property="customAddress" depends="required">
<arg0 key="custom_Adderss"></arg0>
</field>
</form>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~客户信息验证结束结束~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</formset>
</form-validation>

 

2.确认你采用的是validator表单验证,这点在struts-config.xml中会体现

 <form-beans>
    <form-bean name="customForm" type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="customID" type="java.lang.String"></form-property>
 <form-property name="customCardID" type="java.lang.String"></form-property>
 <form-property name="customTele" type="java.lang.String"></form-property>
 <form-property name="customMobile" type="java.lang.String"></form-property>
 <form-property name="customPost" type="java.lang.String"></form-property>
 <form-property name="customAddress" type="java.lang.String"></form-property>
 <form-property name="customContact" type="java.lang.String"></form-property>
 <form-property name="customEmail" type="java.lang.String"></form-property>
 <form-property name="customTime" type="java.lang.String"></form-property>
 <form-property name="customType" type="java.lang.String"></form-property>
 <form-property name="customUnit" type="java.lang.String"></form-property>
    </form-bean>
   
    <form-bean name="customInfoQueryForm" type="org.apache.struts.action.DynaActionForm">
    <form-property name="customID" type="java.lang.String"></form-property>
    <form-property name="customCardID" type="java.lang.String"></form-property>
    <form-property name="customTime1" type="java.lang.String"></form-property>
    <form-property name="customTime2" type="java.lang.String"></form-property>
    </form-bean>
    <form-bean name="wantPageForm" type="org.apache.struts.action.DynaActionForm">
    <form-property name="wantPage" type="java.lang.String"></form-property>
    </form-bean>
 </form-beans>

注意红色部分即可

 

3.根据的自己的需要编辑validation.xml

   根据需要验证的项目以及要求编辑validation.xml,这点较为容易,照猫画虎即可

4.编辑资源文件ApplicationResources.properties   

 

5.最后通过标签<html:errors  property="***" />即可在JSP页面实现验证

 

 

 

注意:保证 input  的name和其他地方的一致性即可

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值