A:action类
package com.bjsxt.struts2.user.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private Stringname;
public Stringadd() {
if(name ==null || !name.equals("admin")) {
this.addFieldError("name","name iserror");
this.addFieldError("name","name is toolong");
returnERROR;
}
returnSUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
B:出错页面
User Add Error!
<s:fielderrorfieldName="name"theme="simple"/>
<br/>
<s:propertyvalue="errors.name[0]"/>
<s:debug></s:debug>
C:struts.xml配置
<constantname="struts.devMode"value="true"/>
<packagename="user"extends="struts-default"namespace="/user">
<actionname="user"class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_add_success.jsp</result>
<resultname="error">/user_add_error.jsp</result>
</action>
</package>
D:缺少验证的结果:?????????