<package name="user" namespace="/user" extends="struts-default">
<action name="*_*" class="com.ouc.wkp.action.UserAction"
method="{2}">
<result>/index.jsp</result>
<result name="error">
/{1}_{2}_error.jsp
</result>
</action>
</package>
struts.xml
package com.ouc.wkp.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String name; public String add() {
// System.out.println(name);
if (name == null) {
this.addFieldError("name", "name is error");
this.addFieldError("name", "name is too long");
return ERROR;
}
return SUCCESS;
}
}
UserAction
<body>
User Add Error!
<s:fielderror fieldName="name" theme="simple">
<br />
<s:property value="errors.name" />
<s:debug></s:debug>
</s:fielderror>
</body>
user_add_error