没有为名称为“成功”的“redirect-action”类型定义结果类型

时间:2013-03-06 09:05:22

标签: java configuration struts2 naming-conventions camelcasing

<action name="saveGetStarted" class="com.sample.action.GetStartedAction" method="save">
      <interceptor-ref name="defaultStack"/>
      <result name="success" type="redirect-action">
          <param name="actionName">preQualification</param>
          <param name="customerId">${customerId}</param>
      </result>
      <result name="input">/jsp/getStarted.jsp</result>
      <result name="error">/jsp/getStarted.jsp</result>
</action>

<action name="preQualification"  class="com.sample.action.PreQualificationAction">
    <result name="success">/jsp/preQualification.jsp</result>
    <result name="input"  >/jsp/preQualification.jsp</result>
</action>

使用struts2-core-2.0.12.jar它可以正常工作,但在更新到struts2-core-2.1.6.jar后,我收到以下错误:

Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success'.  Did you mean 'redirectAction'? - result - file:/D:/eclipse-indigo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Fundation/WEB-INF/classes/struts.xml:19:54
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:613)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:364)
    ... 26 more

导致错误的原因是什么?

3 个答案:

答案 0 :(得分:6)

您正在使用旧表示法来执行操作重定向结果。将redirect-action更改为redirectAction

答案 1 :(得分:5)

在Struts 2.3.x中,一些代码被更改为 redirect-action 更改为 redirectAction

所以你必须这样声明 -

<action name="saveGetStarted" class="com.sample.action.GetStartedAction" method="save">
            <interceptor-ref name="defaultStack"/>
            <result name="success" type="redirectAction">
                <param name="actionName">preQualification</param>
                <param name="customerId">${customerId}</param>
            </result>
            <result name="input">/jsp/getStarted.jsp</result>
            <result name="error">/jsp/getStarted.jsp</result>
          </action>

         <action name="preQualification"  class="com.sample.action.PreQualificationAction"  method="excute">
                <result name="success">/jsp/preQualification.jsp</result>
                <result name="input">/jsp/preQualification.jsp</result>
          </action>

答案 2 :(得分:3)

自Struts 2.1.0以来,所有默认结果名称拦截器名称已从旧版spinal-case更改为Letter case新的camelCase

来自Struts 2.1.1 release version notes

  

以前版本的向后兼容性问题

     

2.1.0以来:所有默认结果名称和拦截器名称现在都在camelCase中(例如redirect-action,现在是redirectAction

     

...