struts2页面输出错误信息

<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

 

posted @ 2016-08-03 22:14  docyard  阅读(368)  评论(0编辑  收藏  举报