Struts2 Validation using validation.xml Netbeans Example

Struts2 provides different validation methods. In this post basic validation method is described that uses the validation.xml file.
 
File Structure

validation_struts2_file_structure_netbeans

 
—index.jsp—

 
—Register.java—

 
—struts.xml—

 
—Register.validation.xml— (Place this file in the folder where your Register.java is)

 

There are other pages also. Download the complete program.
Validation_Struts2_Mvn_Netbeans.rar

 
OUTPUT

validation_output_eclipse

source: http://struts.apache.org/release/2.0.x/docs/validation.html

xml Validation Struts2 Example

Struts2 provides different validation methods. In this post basic validation method is described that uses the validation.xml file.

File Structure

validation_struts2_file_structure_eclipse
—index.jsp—

Struts 2 Validation Example

 
—Register.java—

—struts.xml—

—Register.validation.xml— (Place this file in the folder where your Register.java is)

 

There are other pages also. Download the complete program.
Validation_Struts2_Mvn_Eclipse.rar

OUTPUT

validation_output_eclipse

source: http://struts.apache.org/release/2.0.x/docs/validation.html

Struts 2 Validation

Struts 2 is a very powerful open source web application framework. It was originally created by
Craig McClanahan and donated to the Apache Foundation in May, 2000.
It is also called Jakarta Struts.
It has several features, following are the features of the Struts 2…

  • Simple POJO based Actions
  • Simplified testability
  • Thread Safe
  • AJAX Support
  • jQuery Plugin
  • Dojo Plugin (deprecated)
  • AJAX Client Side Validation
  • Template Support
  • Support for different result types
  • Easy to extend with Plugins
  • REST Plugin (REST based Actions, Extension-less URLs)
  • Convention Plugin (Action Configuration via Conventions and Annotations)
  • Spring Plugin (Dependency Injection)
  • Hibernate Plugin
  • support in Design
  • JFreechart Plugin (Charts)
  • jQuery Plugin (AJAX Support, UI Widgets, Dynamic Table, Charts)
  • Rome Plugin (RSS Feeds)

The feature of Struts2 that attracts me the most is the validation part of the struts 2 . If you do not use the struts 2 validation for the form validation purpose you have to use the  JavaScript  , but using JavaScript is a very lengthy and complex process and you have to write a large code to validate a single field. so if you are working with struts2 , it is a best option to use struts validation in place of  JavaScript or AJAX because struts2 do it easy for you.

It is explain as follows.
Example:

 

Note: the validation file name should be carefully written
Format for name is

example NewTeacher-validation.xml file should be kept in the folder where your action file is located

—NewTeacher-validation.xml—(validation file)

—NewTeacher.java—(action class)

—newTeacher.jsp—

—struts.xml—