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


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
	Struts 2 Validation Example

Struts 2 Validation Example


package org.apache.struts.helloworld.action;

import com.opensymphony.xwork2.ActionSupport;

public class Register extends ActionSupport {
	 * @author ABHISHEK
	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";   





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

                Name is required
                Email is required

                 Enter valid Email


There are other pages also. Download the complete program.



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