参数"方法"不起作用(Struts 1)

Dav*_*vid 1 java jsp struts struts-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>
Run Code Online (Sandbox Code Playgroud)

在我的JSP页面中,我有以下形式:

<html:form action="/updateAccountInfo.do">
    <input type="hidden" name="method" value="sendMessage" />
Run Code Online (Sandbox Code Playgroud)

在我的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;
}
Run Code Online (Sandbox Code Playgroud)

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

Jör*_*ann 8

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

  • 我重写了execute方法.这似乎打破了DispatchAction调用逻辑的方法.... (2认同)