Validator for adjusting CommON in Spring

xiaoxiao2021-03-06  50

The first is to first put some of the CommON's bags in Spring in your / web-inf / lib .. all the packages in% Spring_Home% / lib / jakarta-commons ... and a comparison Important Spring-Sandbox.jar This package must be placed in your lib .. Because our BeanValidator and the ValidatorFactory class are in this spring-sandbox.jar ..

Next is what we want a validator-rules.xml. We are more common rules files ... You can copy the validator-rules.xml in Struts. It is possible .. There is a required. Minlength maxlength ..., etc. Rules, etc.

Then the value of validation.xml .. I believe that friends who have used struts know .. In this file, it defines the verification of Properties in the FormBean ... So in Spring .. Said, you can copy the validation.xml in Spring to Spring in Spring ...

Next is the definition of Validator in action-servlet.xml.. /web-inf/validation.xml /web-inf/Validator-rules.xml

should pay attention to Be sure to have spring-sandbox.jar this package .. Because org.springframework.validation.commons.beanvalidator and org.springframework.validation.commons.defaultValidatorFactory is in this package .. Otherwise .. Your app Server will have Error Message that these two classes cannot be found ..

Defined in validation.xml:

This step is the same as you defined in Struts ... .

Then insert the validator into our action: user model.user < Value> Middle final should pay attention to .. Value in CommandName in this is User .. must be the same as the properties of Name in the Form in Validation.xml .. 也 user is corresponding ...

Then you have to verify our JSP into our verification .. This step is also the same as in Struts .. Add: At this time You should pay attention to our HTML: JavaScript a tab.. <% @ Taglib Uri = "http://www.springframework.org/tags/commons-validator" prefix = "html"%> is to use this One .. rather than <% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html"%> that time ... because I used <% @ Taglib URI = "http://jakarta.apache.org/struts/tags-html" prefix = "html"%> This one ... then always make an error .. Harm I checked a whole day .. Halo ... huh, huh ..., so I have to pay attention to the following: 1. Remember to join the Spring-Sandbo.jar this package and the jakarta-commit lower package. .2. Pay attention to form name = "user" in validation.xml, in the action should be consistent .. 3. Don't think it is <% @ taglib uri = "http://jakarta.apache.org/struts/tags-html" Prefix = "html"%> ... must use <% @ Taglib URI = "http://www.springframework.org/tags/commons-validator" prefix = "html"%> This bid library ..

转载请注明原文地址:https://www.9cbs.com/read-115544.html

New Post(0)