取消按钮,没有任何操作方法抛出和异常

问题描述 投票:0回答:1

当单击取消按钮时,我当前正在查看的 Struts (1.x) 代码(已有 12 年历史)出现问题。这是带有操作方法的 java 代码:

public class CustomerApproveTypeAction extends AbstractCustomerApproveTypeAction {
    private final Log log = LogFactory.getLog(CustomerApproveTypeAction.class);
 
    public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'edit' method - QS: " + request.getQueryString());
        }
 
            return mapping.findForward("edit");
        }
 
         
        return mapping.findForward("home");
    }
 
    /**
     * Save the info from the screen (being edited)
     * 
     * 
     */
    public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'save' method...");
        }
 
         
        return new ActionForward("/report.html?meth=viewResult&bc=" + kc);
    }
 
    /**
     * Approve the info from the screen (being edited)
     * 
     * 
     */
    public ActionForward approve(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'approve' method...");
        }
 
         
        return new ActionForward("/report.html?meth=viewResult&kc=" + kc);
    }
     
     
    public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        return mapping.findForward("home");
    }
 
}

以下是从 JSP (customerApproveType.jsp) 调用所有方法的方式,并且当单击 Approve 和 Save 按钮时它们都可以正常工作。

<tr>
            <td colspan="2" align="center">
<html:submit
                    styleClass="button" property="approve"
                    onclick="this.form.meth.value='approve'">Approve</html:submit>
                </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
<html:submit
                    styleClass="button" property="save"
                    onclick="this.form.meth.value='save'">Save</html:submit> <html:cancel
                    styleClass="button">Cancel</html:cancel></td>
        </tr>

但是,一旦单击取消按钮,我就会不断收到:

[INFO] SEVERE: Servlet.service() for servlet [action] in context with path [/myapp] threw exception [java.lang.NoSuchMethodException: Action[/customerApproveType] does not contain specified method (check logs)] with root cause
[INFO] java.lang.NoSuchMethodException: Action[/customerApproveType] does not contain specified method (check logs)
 
so on and so forth ....
 
[INFO] org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported

这是我的

AbstractCustomerApproveTypeAction
课程:

public abstract class AbstractCustomerApproveTypeAction extends DispatchAction {
 
    public ActionMessages validateForm(ActionForm form, HttpServletRequest request) {
    }
 
    protected void mapFormToBean(UpdateCustomerForm updateCustomerForm, Order order) {
 
    }
 
    private void fillCustomer(CustomerHandler cph, Order order) {
 
    }
    protected CustomerHandler updateOrderUsingId(Order order, Integer userId) {
 
    }
    protected void updateCtrfile(Order order, Case cs) {
         
    }
    protected CustomerFile makeCustomerFile(Order order, Case cs, CustomerHandler cph, Manager mgr) {
         
        return customerFile;
    }
}

struts-config.xml
,其中 bean 是为
CustomerApproveTypeAction

定义的
<bean name="/customerApproveManual"
        class="com.abc.web.CustomerApproveTypeAction"
        scope="prototype">
        <property name="orderManager">
            <ref bean="orderManager" />
        </property>
         
</bean>

因为取消按钮没有像其他按钮(例如

onclick="this.form.meth.value='save'"
)那样的 onclick 事件。如果我的想法不正确,请解释一下。我想我可以为取消按钮定义一个操作方法,并像
"onclick="this.form.meth.value='cancel'"
那样调用它,但我希望
unspecified
方法能够处理它。

java struts-1
1个回答
0
投票

对于

<html:cancel>
按钮,已经映射了一个名为
cancelled
的方法。您所需要的只是将此方法添加到您的操作类中。

DispatchAction
:

如果请求参数的值为空,则调用名为

unspecified
的方法。默认操作是抛出异常。如果请求被取消(按下
<html:cancel>
按钮),则将使用自定义处理程序
cancelled
。您还可以覆盖
getMethodName
方法来覆盖操作的默认处理程序选择。

© www.soinside.com 2019 - 2024. All rights reserved.