Precautions for configuring validator in spring MVC in JSP, springmvcvalidator
SpringMVC introduction to Validation
For any application, the Data Validity verification on the client is not safe and effective. At this time, we are required to verify the data validity on the server during development. SpringMVC has a good support for data validation on the server. It can verify the data validity of the data submitted to the server according to our prior Conventions, springMVC stores Unqualified Data Information in error objects. The error information can also be displayed on the front-end JSP page through the labels provided by SpringMVC.
Precautions for configuring validator in springmvc
<mvc:annotation-driven validator="validator" />
When using spring MVC to integrate hibernate-validator for form data verification (the page label uses the form related labels of spring), I do not know whether it is due to version or other reasons, the preceding configuration must be placed at the beginning, and the data verification comments (such as @ size and @ email) will take effect. The error binding class can receive the error message.
In addition, let's talk about the difference between spring-servlet.xml and applicationContext. xml in springmvc:
1: The spring-servlet.xml reads and loads the configuration when dispatcherServlet is started. applicationContext. xml is loaded when contextLoaderListener listens to the server;
2: When springmvc's dispatcherServlet is not used as the control layer (for example, struts2), applicationContext. xml can be used independently to configure all spring-related things; when used together there are some specifications, the spring-servlet.xml is better to load beans containing Web components, such as controllers, view parsers and processor ing, while contextLoaderListener needs to load other beans in the application. These beans are usually the middle layer and data layer components driving the application backend.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!