Parameter “method” not working (Struts 1)

南笙酒味 提交于 2019-12-20 05:23:24

问题


I have the following action declared in my 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>

In my JSP page, I have the following form:

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

In my java class, I have the following method:

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

Instead of running sendMessage, Struts call the execute method. Why? Is my struts-config wrong? Or am I missing another config setting?


回答1:


Please first make sure that your action extends DispatchAction. You probably should not override the execute method in that class since that method is responsible for extracting the request parameter and invoking the corresponding method. If you override execute this logic will no longer execute.




回答2:


Does your UpdateAccountAction extend DispatchAction? Here's a working example that does what you're trying to do.




回答3:


First thing is that in html:form action="/updateAccountInfo.do"> you have mentioned updateAccountInfo.do and want to call the sendMessage. How it is possible?? It is different.

Other thing is is that your need require the dispatch action rather action class. It seem you require multiple method to call in struts so it is recommended to use dispatchaction class.

Refer mkyon site for more details about how to use dispatch action and when it is required.



来源:https://stackoverflow.com/questions/3310170/parameter-method-not-working-struts-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!