在開發中總遇到這個問題,No result defined for action:
原因:Action中的屬性值為空的時候,Struts2的默認攔截器會報錯,但是又找不到input的Result,不能夠把錯誤返回,所以報這種錯誤。
解決方法:
1.在頁面中給空值賦默認值。
2.重新定義一個Action,去掉空值的成員變量。
3.添加input的Result,并在這個頁面給出提示
--------------------------------------------------------------------------
當你在用struts2開發時,如果,從頁面跳入action時,頁面報No result defined for action and result時,大部分的原因有以下幾種:
1、validate方法沒有通過;
2、頁面元素中有重命名時,但后臺action類的對應的接收此同名參數的是變量而沒有寫成數組
要檢查這種錯誤時,可以
1,在后臺action類中重寫ActionSupport中的
void addActionError(String anErrorMessage)
void addActionMessage(String aMessage)
void addFieldError(String fieldName, String errorMessage)
這三個方法,在并在其實現代碼中設置斷點,監控傳入的參數,并可獲知頁面的相關報錯具體原因.
2,在頁面中加入以下標簽,將錯誤顯示出來 :
< div style =”color:red” >
< s:fielderror />
</ div >
--------------------------------------------------------------------------
public void addActionError(String anErrorMessage){
String s=anErrorMessage;
System.out.println(s);
}
public void addActionMessage(String aMessage){
String s=aMessage;
System.out.println(s);
}
public void addFieldError(String fieldName, String errorMessage){
String s=errorMessage;
String f=fieldName;
System.out.println(s);
System.out.println(f);
}
來自:
http://www.itstrike.cn/Question/9eeeed8e-8a75-4f53-bde7-d0c0a2a6f1e6
posted on 2011-07-20 10:02
墻頭草 閱讀(66315)
評論(8) 編輯 收藏