Validator验证框架

struts学习笔记]Validator验证框架 小结:struts中应用validator框架的一般步骤(结合实例) 1 创建扩展ValidatorForm或者ValidatorActionForm类的ActionForm类,如果使用动态的ActionForm类,则无需创建扩展DynaValidatorForm或DynaValidatorActionForm类的子类,可直接进行第2步。 eg:registrationForm.java import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMessage; import org.apache.struts.validator.ValidatorForm; public class registrationForm extends ValidatorForm { …………………… } 2 在struts配置文件struts-config.xml中配置

和元素。 eg:struts-config.xml 3 把Validator框架使用的消息文本添加到应用的Resource Rundle中。 eg:ApplicationResources.properties # Struts Validator Error Messages errors.required={0} is required. errors.minlength={0} can not be less than {1} characters. errors.maxlength={0} can not be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be a byte. errors.short={0} must be a short. errors.integer={0} must be an integer. errors.long={0} must be a long. errors.float={0} must be a float. errors.double={0} must be a double. errors.date={0} is not a date. errors.range={0} is not in the range {1} through {2}. errors.creditcard={0} is an invalid credit card number. errors.email={0} is an invalid e-mail address. 4 在validator.xml配置文件中为表单配置验证规则。 eg:validator.xml
maxlength 16 minlength 3

5在struts的配置文件struts-config.xml中配置ValidatorPlugIn插件。 eg:struts-config.xml

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值