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—







    
        Struts 2 Validation Example

Struts 2 Validation Example

 
—Register.java—

package p3lang.actions;

/**
 *
 * @author ABHISHEK
 */
import com.opensymphony.xwork2.ActionSupport;

public class Register extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	private String name;
	private String email;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	 public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String execute() 
	    {
	        return "success";
	        
	    }	
}

 
—struts.xml—



index.jsp/Success.jsp/ValidationFailed.jsp

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

Name is requiredEmail is requiredEnter valid Email

 

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