Validation introduced by Spring MVC
For any application, data validation on the client side is not safe and effective, which requires us to validate the validity of data on the server side at the time of development. Spring MVC itself has a good support for data validation on the server side. It can validate the data submitted to the server according to our prior agreement. Spring MVC will save the unqualified data information in the error object. These error information can also be displayed on the front-end JSP page through the tag provided by Spring MVC.
Notes on Spring MVC configuration validator
<mvc:annotation-driven validator="validator" />
When using Spring MVC to integrate hibernate-validator for form data validation (page tags use spring form-related tags), it is not known whether it is due to version or other reasons. It is necessary to put the above configuration in the front, data validation annotations (e.g. @size, @email, etc.) will take effect, and error binding classes will receive error information.
In addition, let’s talk about the differences between spring-servlet.xml and application Context.xml in spring mvc.
1:spring-servlet.xmlIt reads and loads the configuration when dispatcher Servlet starts. ApplicationContext. XML is loaded when contextLoaderListener hears the server starts.
2: Not in useSpring MVC dispatcher ServletIn the control layer (such as struts2), application Context. XML can use all spring-related configurations separately; when used together, there are some specifications. Spr-servlet. XML is best loaded with beans containing Web components, such as controllers, view parsers and processor mappings, while contextLoaderListener loads other beans in the application, which are usually Drive the mid-tier and data-tier components of the application backend.
Thank you for reading, I hope to help you, thank you for your support on this site!