4
<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

是什么导致了错误?

4

3 回答 3

6

您正在为动作重定向结果使用旧符号。更改redirect-actionredirectAction

于 2013-03-06T09:10:14.390 回答
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>
于 2013-03-06T11:58:03.960 回答
3

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

来自Struts2.1.1发行版说明

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

由于2.1.0:所有默认结果名称和拦截器名称现在都采用 camelCase 格式
(例如 was redirect-action, is now redirectAction

...

于 2013-03-06T09:11:47.630 回答