Javatpoint Logo
Javatpoint Logo

Spring MVC Custom Validation

The Spring MVC framework allows us to perform custom validations. In such case, we declare own annotations. We can perform validation on the basis of own business logic.


Spring MVC Custom Validation Example

In this example, we use both pre-defined annotations as well as custom annotations to validate user input.

1. Add dependencies to pom.xml file.

pom.xml

2. Create the bean class

Employee.java

3. Create the controller class

EmployeeController.java

4. Create the validator annotation

Password.java

5. Create the validator class

PasswordConstraintValidator.java

6. Provide the entry of controller in the web.xml file

web.xml

7. Define the bean in the xml file

spring-servlet.xml

8. Create the requested page

index.jsp

9. Create the other view components

viewpage.jsp

final.jsp

Output:

Spring MVC Custom Validation
Spring MVC Custom Validation

Here, we entered the password without having "jtp" sequence.

Spring MVC Custom Validation
Spring MVC Custom Validation

Now, we entered the password having "jtp" sequence.

Spring MVC Custom Validation
Spring MVC Custom Validation




Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA