SoFunction
Updated on 2025-03-09

Notes on springmvc configuration validator in JSP

SpringMVC introduction Validation

For any application, data validation on the client is not safe and effective. At this time, we are required to verify the validity of the data on the server during development. SpringMVC itself has a good support for the verification of data on the server. It can verify the data submitted to the server according to our prior agreement. SpringMVC will save it in the error object for unqualified data information. We can also display these error information on the front-end JSP page through the tags provided by SpringMVC.

Notes on springmvc configuration validator

<mvc:annotation-driven validator="validator" /> 

When using springmvc integration hibernate-validator for form data verification (the page tag uses spring form-related tags), I don’t know if it is due to version or other reasons, the above configuration needs to be placed at the front, and the data verification annotation (for example: @size, @email, etc.) will take effect, and the error binding class can receive the error message.

In addition, let’s talk about the difference between springmvc:

1:The configuration is read and loaded when the dispatcherServlet is started. It is loaded when the contextLoaderListener listens to the server startup;

2: Not usedspringmvc dispatcherServletWhen working on the control layer (such as struts2), you can use it to configure all spring-related things separately; when used together, there are some specifications, it is best to load beans containing web components, such as controllers, view parsers, and processor mappings, while contextLoaderListener needs to load other beans in the application, which are usually the intermediate layer and data layer components that drive the application backend.

Thank you for reading, I hope it can help you. Thank you for your support for this site!