Validator验证框架

来源:互联网 发布:mysql float 精度 编辑:程序博客网 时间:2024/06/09 16:06

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