1

我在我的 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错了吗?还是我错过了另一个配置设置?

4

3 回答 3

8

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

于 2010-07-22T15:13:49.483 回答
1

您的 UpdateAccountAction 是否扩展 DispatchAction? 这是一个工作示例,可以执行您尝试执行的操作。

于 2010-07-22T15:12:39.527 回答
0

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

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

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

于 2010-12-09T11:25:28.330 回答