简体   繁体   English

Struts2提交按钮方法调用不会触发

[英]Struts2 submit button method call doesn't fire

I am having problems with the below code, can anyone explain why the method may not be being fired on the jobListAction? 我的以下代码有问题,任何人都可以解释为什么未在jobListAction上触发该方法的原因吗? 'Setup' is being called twice upon submission of the form. 提交表单后,将两次调用“设置”。 In short, I can't seem to get the struts button to call multiple methods. 简而言之,我似乎无法获得Struts按钮来调用多个方法。 Any pointers / things to check? 任何指针/要检查的东西?

public class JobListAction {
    public String execute() {
        System.out.println("setup");
    }

    public String deactivate() {
        System.out.println("called");
    }
   public String callonme()
   {
   }
} 

JSP: JSP:

<s:form id="recordsListForm" method="post" action="jobList">
 <s:submit type="button" action="deactivate" value="Deactivate Selected Jobs" method="deactivate" />
 <s:submit type="button" action="callonme" value="CallonMe" method="callonme" />

</s:form>

Struts.xml Struts.xml

    <!-- Job List -->
    <action name="jobList" class="JobListAction">
        <result name="input">/jsp/admin/jobList.jsp</result>
        <result name="success">/jsp/admin/jobList.jsp</result>
    </action>

    <!-- Job List - Deactivate Job -->
    <action name="deactivate" class="JobListAction" method="deactivate">
        <result name="input">/jsp/admin/jobList.jsp</result>
        <result name="success">/jsp/admin/jobList.jsp</result>
    </action>

    <action name="callonme" class="JobListAction" method="callonme">
        <result name="input">/jsp/admin/jobList.jsp</result>
        <result name="success">/jsp/admin/jobList.jsp</result>
    </action>

I guess in struts 2 u need to tell the method name in Struts.xml file, try that out, I hope it works... 我想在struts 2中您需要在Struts.xml文件中告诉方法名称,尝试一下,我希望它能起作用...

<action name="jobList" class="JobListAction" method = "deactivate">
  <result name="input">/jsp/admin/jobList.jsp</result>
  <result name="success">/jsp/admin/jobList.jsp</result>
</action>

If you want to have a single action declaration that can call multiple methods in the same action class, look into using wilcard mappings : 如果您想拥有一个可以在同一个动作类中调用多个方法的动作声明,请考虑使用通配符映射

View 视图

<s:form id="recordsListForm" method="post" action="jobList">
   <s:submit type="button" action="jobList_deactivate" value="Deactivate Jobs" />
   <s:submit type="button" action="jobList_callonme" value="CallonMe" />
</s:form>

struts.xml struts.xml

<!-- Job List -->
<action name="jobList_*" method="{1}" class="JobListAction">
    <result name="input">/jsp/admin/jobList.jsp</result>
    <result name="success">/jsp/admin/jobList.jsp</result>
</action>

The above mapping will match any action that starts with jobList_ and then use the rest of the match as the method to call in the JobListAction class. 上面的映射将匹配任何以jobList_开头的action ,然后将其余的匹配用作在JobListAction类中调用的方法。

Works fine for me; 对我来说很好; what version? 什么版本的? Is dynamic method invocation enabled (it is by default)? 是否启用了动态方法调用(默认情况下)?

What do you mean by "call multiple methods?" “调用多种方法”是什么意思? You can only call a single method per-request. 每个请求只能调用一个方法。

My stdout: 我的标准输出:

setup // On initial form display
called // Clicking submit

Cut-and-pasted your code (more or less) verbatim. 逐字剪切(或多或少)粘贴您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM