bestlong 怕失憶論壇's Archiver

bestlong 發表於 2011-4-21 11:13

[struts2] No result defined for action XXX and result input

使用 struts 2.2.1.1 持續的增加程式, 瀏覽原本正常的 /webapp/employee.action 畫面突然出現錯誤

No result defined for action action.EmployeeAction and result input

當時在 struts.xml 中的設定[code]
        <action name="employee" class="action.EmployeeAction">
                <result name="add">/WEB-INF/view/employee-add.jsp</result>
                <result name="edt">/WEB-INF/view/employee-add.jsp</result>
                <result>/WEB-INF/view/employee.jsp</result>
        </action>
[/code]在 Action 的相關程式碼部分[code]
package action;
public class EmployeeAction extends BaseAction implements SessionAware {
        public static final String ADD = "add";
        public static final String EDIT = "edt";
        private Employee employee = null;

        public String execute() {
                System.out.println("CHECK");
                if(ADD.equals(action)) {
                        this.employee = null;
                        return ADD;
                }
                if(EDIT.equals(action)) {
                        this.employee = dao.findById(this.id);
                        return EDIT;
                }
                return SUCCESS;
        }
}[/code]不知道為何會去找 result input

bestlong 發表於 2011-4-21 11:53

結果是因為增加了驗證設定檔 EmployeeAction-validation.xml

因為驗證機制是需要輸入
所以當瀏覽的頁面是沒有時
驗證機制就會產生 result input
而 struts.xml 中又沒有設定就會出現此錯誤
頁: [1]

Powered by Discuz! X1.5 Archiver   © 2001-2010 Comsenz Inc.