【问题标题】:Parameter "method" not working (Struts 1)参数“方法”不起作用(Struts 1)
【发布时间】:2010-07-22 14:50:41
【问题描述】:

我在我的 struts.xml 中声明了以下操作:

    <action path="/updateAccountInfo"
            type="org.myCompany.UpdateAccountAction"
            name="myAccountForm"
            scope="session"
            validate="true"
            parameter="method" 
            input="/updateAccountInfo.jsp">
        <forward name="success" path="/updateAccountInfo.jsp" />
    </action>

在我的 JSP 页面中,我有以下表单:

<html:form action="/updateAccountInfo.do">
    <input type="hidden" name="method" value="sendMessage" />

在我的 java 类中,我有以下方法:

public final ActionForward sendMessage(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    System.out.println("sending");
    return null;
}

Struts 调用execute 方法而不是运行sendMessage。为什么?我的struts-config错了吗?还是我错过了另一个配置设置?

【问题讨论】:

    标签: java jsp struts struts-1


    【解决方案1】:

    请首先确保您的操作扩展了 DispatchAction。您可能不应该覆盖该类中的 execute 方法,因为该方法负责提取请求参数并调用相应的方法。如果您覆盖执行,此逻辑将不再执行。

    【讨论】:

    • 我重写了执行方法。这似乎打破了 DispatchAction 的方法调用逻辑......
    【解决方案2】:

    您的 UpdateAccountAction 是否扩展 DispatchAction? Here's a working example 做你想做的事。

    【讨论】:

    • 是的,它确实扩展了 DispatchAction。我将尝试将我的代码与示例进行比较,看看是否能发现任何差异.....
    【解决方案3】:

    第一件事是在 html:form action="/updateAccountInfo.do"> 你提到了 updateAccountInfo.do 并且想要调用 sendMessage。怎么可能??不一样。

    另一件事是您需要调度动作而不是动作类。看来你需要多个方法来调用struts所以建议使用dispatchaction类。

    请参阅 mkyon 网站以获取有关如何使用调度操作以及何时需要它的更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2015-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多