struts2页面输出错误信息
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<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>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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; } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<body> User Add Error! <s:fielderror fieldName="name" theme="simple"> <br /> <s:property value="errors.name" /> <s:debug></s:debug> </s:fielderror> </body>