Struts 2 Validation Tutorial
To avoid the wrong values, we need to perform validation on forms where user submits some values. For example, if user writes his/her email id as abc, we need to give error message to the user that the given email id is not correct. So that we can have only valuable informations.
There are three ways to perform validation in struts 2.
1) By Custom Validation Here, we must implement the Validateable interface (or extend ActionSupport class) and provide the implementation of validate method.
2) By Input Validation (built-in validators) Struts 2 provides a lot of predefined that can be used in struts 2 application to perform validation.
Struts 2 provides following bundled validators.
- requiredstring validator
- stringlength validator
- email validator
- date validator
- int validator
- double validator
- url validator
- regex validator
3) By Ajax Validation (built-in validators with ajax) If we don’t want to refresh the page, we can use jsonValidation interceptor to perform validation with ajax.