gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 08:11:53 25 4
gpt4 key购买 nike

我在使用以下代码时遇到问题,谁能解释为什么该方法可能不会在 jobListAction 上被触发?提交表单后,“设置”被调用两次。简而言之,我似乎无法获得调用多个方法的struts 按钮。有什么要检查的指示/事项吗?

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

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

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

    <!-- 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>

最佳答案

我想在 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>

关于java - Struts2 提交按钮方法调用不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7696738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com