MyEclipse 9.0 Struts2 动态结果使用问题

来源:互联网 发布:电子杂志制作软件排行 编辑:程序博客网 时间:2024/05/12 22:54

 最近在使用MyEclispe9.0 用到struts2 时遇到了点小问题,整了个偏方拿出来晒晒吧!

Myeclipse9 struts2 动态结果的使用问题
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>

先到这儿吧,如果有哪位同学有更好的解决方法,请告知谢谢!