Struts Validator Example

In this tutorial we learn how Struts is using Validator framework.

Generally in Struts1 we will write validate() method in form bean to validate the form data, some times it is bit difficult to manage our validation logic in validate method some times we might need to write duplicated code , to address these kind of  issue we have a powerful mechanism called Validator framework which will support by Struts frame work, by using this Validator framework we can make the Struts validation more standardization, reusable and less duplicated code

Let us have a look in to the below example.

Technologies used in this article :

1. Struts1.3
2. Maven 1.4
3. Eclipse 4.2
4. JDK 1.5

1. Create Maven Web project in Eclispe and add the Maven  dependencies like as as below Maven’s pom.xml file. 

2. Implement the Form bean named “RegisterForm” .

 3. Implement the Action class   “”.

4. Configure the Action Class and form bean in struts-config.xml like as below.

Use <plug-in> tag  to configure the our validation.xml and validator-rules.xml files.

5. Define the validation rules to validation.xml .

Define the validation rules for form fields in this file .

 5. properties file

 6. jsp file.

 7 . Finally  Project Structure in Eclipse should like as below.



deploy & run the application in tomcat by accessing below URL, test it with respect the rules defined in validation.xml.

if you not entered the valid data, it will show the errors accordingly.




Enter the valid data and submit the request, it will go to success.jsp with out any error.


If all the form data is valid then you will find below output.


Download  Source Code



Posted in struts and tagged , .

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.