Myeclipse9 struts2 ${nextAction}動態結果配置報錯問題

struts.xml中正常配置action,result的指向使用動態的方式即:
public class ActionOne extends ActionSupport{

private String forward="index.jsp";

public String getForward() {
return forward;
}

public void setForward(String forward) {
this.forward = forward;
}

public String execute(){
return Action.SUCCESS;
}

}
xml:
<action name="one" class="actions.ActionOne">

<!--這裏提示出錯:Invalid result location value/parameter-->

<result>/${forward}</result>

</action>

同樣的程序到了myeclipse7 或者myeclipse 8.5顯示正常,運行時不影,可以正常運行(只是看得難受)!

問題出在哪兒具體不太清楚,我想可能是myeclipse9 這個版本不打算對struts2動態結果這方面不大支持,或者驗證文件有問題,個人猜測!

試了一個簡單的解決方法:更改xml爲如下,

<action name="one" class="actions.ActionOne">

<!--報錯問題解決-->

<result type="redirect">/${forward}.jsp</result>

</action>
當然在action中對forward的賦值也要相應改成:forward="index";

解決方案分析:

經此配置後動態結果不能跳轉到完整的頁面路徑,導致每一種跳轉類型及跳轉的每一種文件類型的路徑都得爲其配置一result

由如上配置將只能用於到JSP面頁的跳轉,如要跳轉到html頁面得另配:

<action name="one" class="actions.ActionOne">
<!--報錯問題解決-->
<result>/${forward}.jsp</result>
<result name="html">/${forward}.html</result>
</action>

先到這兒吧,如果有哪位同學有更好的解決方法,請告知謝謝!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章