import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private String name;
public String add() {
if(name == null || !name.equals("admin")){
this.addFieldError("name","name is error");
return ERROR;
}
System.out.println("name=" + name);
return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
jsp页面引入struts标签获得错误信息
头部加入
<%@taglib uri="/struts-tags" prefix="s" %>
取得错误信息
<s:fielderror fieldName="name" theme="simple"></s:fielderror>
调试标签
<s:debug></s:debug>