This video tutorial of Spring 3 MVC Framework will teach you about validating user input in the form. Spring 3 MVC framework's validation API is very powerful and you can validate user input easily. You can also extend the validation framework and write your own validation rules.
Based on a model view architecture, the open source framework of spring web MVC is used to build loosely coupled and scalable web applications. It segregates various components of the application like business logic, UI logic and input logic at the same time ensuring loose coupling within the components. It is designed using the DispatcherServlet which caters to the HTTP responses and requests.
This video shall elucidate the validation of a form based on Spring 3 MVC. For validation of form data, Hibernate validator is used. The form would exhibit a simplified form of user registration from the user. The 3 fields to be chosen from should include User name, Age and the password.
In the JSP page, the user name is taken in between 10-20, password within 1- 10 characters and the age should not exceed 110.
The must use annotations are notEmpty, size(min=1,maz=20), NotNull, NumberFormat(style=Style NUMBER), Min(1), Max(10), NotEmpty(message=”Password must not be blank”),Size(min=1,max=10,message=”Password must be between 1 to 10 characters”)
In the validation form.java section you will find the validation form displayed along with the given entries in the page. Next comes the validationcontroller page which saves the data to the data base . This is completed by validationform.jsp where the form fields along with the password would create the user registration page.
Here is the video tutorial of "How to validate a form in Spring MVC 3?":
Thus the precise steps include:
- Creating the index.jsp which is under webcontent.
- Next create model class”ValidationForm Java” under src folder
- Next create the views of the folder headed under webcontent/WEB-INF and the validationform jsp which is under WebContent/WEB-INF
- Next create “validationsuccess jsp” under file WebContent/WEB-INF
- Build a controller class “ValidatonController java” under src folder
- Modification of web Xml(this will include the dispatcher servlet)
- Create a “dispatcher-servlet Xml” placed under WebContent/WEB-INF
- Finally run the application display output
Download source code from roseindia.net website.
More pages of Spring Tutorials:
Spring 3 MVC Online Test Application
Spring 3 MVC upload ,view and save image
Spring 3 MVC Hello World Example
Spring 3 MVC insert/retrieve blob in database
Spring 4 MVC Hello World Tutorial Video tutorial
[ 0 ] Comments