Struts_Validate_Method_Notes
Struts_Validate_Method_Notes
-----------------------------------------------------------
In the Struts framework, the `validate()` method is used to check the validity of form data submitted
by the user.
It is defined inside a class that extends `ActionForm`. When a user submits the form, Struts
automatically calls
this method to perform form validation before the `execute()` method in the Action class runs.
If the `validate()` method finds any errors, the form is re-displayed to the user with appropriate error
messages.
----------------------------------
Let's say we have a `UserForm` with two fields: `name` and `email`. We want to validate that:
```java
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
return errors;
```
How It Works:
-------------
3. If `errors` is not empty, the form is shown again with error messages on the JSP page.
----------------------
Resources:
----------
- https://websparrow.org/struts/struts2-validation-example-using-validate-method-and-xml-file
- https://www.tutorialspoint.com/struts_2/struts_validations.htm