软讯网络 > 编程语言 > Java > 使用Struts-Validator常见错误[经典]
【标 题】:使用Struts-Validator常见错误[经典]
【关键字】:
Struts-Validator
【来 源】:http://blog.csdn.net/patriotlml/archive/2006/05/31/766353.aspx
使用Struts-Validator常见错误[经典]

最近一段时间忙着用struts-Validator作毕业设计,遇到了一些问题,老是出错,从网上找到这篇文章,真是经典,赶忙收藏起来,以备来日大用。
Make sure you have the following: 1) ApplicationResources.properties file with keys/values for standard validators (at least - errors.required) 2) struts-config.xml file should contain the reference to this resource file for message-resources node. 3) struts-config plug-in node should contain validator Plugin className="org.apache.struts.validator.ValidatorPlugIn" 4) The plugin should have set-property with name pathnames that corresponds to validator files (such as /WEB-INF/validator-rules.xml and /WEB-INF/validation.xml) 5) Action Validation vs. Form Validation. Alternative solutions: Solution A: - Form Validation: validation.xml should contain form with name that corresponds to form-bean name in struts-config. - Form Bean or its Parent should inherit org.apache.struts.validator.ValidatorForm class Solution B (povides more flexibility):- - Form Validation: validation.xml should contain form with name that corresponds to action’s path name in struts-config. - Form Bean or its Parent should inherit org. apache.struts.validator.ValidatorActionForm. 6) The form should have a field with property that corresponds to field name we want to validate. Nested properties are okay. 7) This field should have a 'depends' attribute that corresponds to the validator name mentioned in /WEB-INF/validator-rules.xml (i.e. 'required') 8) This field should have an arg0 node with attribute key that corresponds to existing key in application resource file 9) in action-mapping: 'input' attribute of action should reference to jsp page with validated form and validate should be set to true. 12) jsp page should contains <html:errors /> (or its substitute) File Compatibility: 1) Make sure the validation-rules.xml and commons-validator.jar match. The xml version and jar’s implementation version need to be compatible 2) Make sure your struts.jar version is compatible with the commons-validator.jar 3 ) Compabitly issues will usually result in validation not working and no errors or warnings to trace the problem. To avoid issues, simply do not attempt to reuse other's validation.xml, validation-rules.xml, and commons-validator.jar files. Only use files that are packaged with your struts distribution zip/tar file.
【相关文章】
没有相关文章