【发布时间】:2015-08-03 16:44:40
【问题描述】:
我一直在处理这种情况。在我的 Struts 2 应用程序中,我使用 AJAX 调用将字符串数组发送到 Action 类。我想做的是这样的:page_1.jsp -> Action A -> Action B -> Action C。然而,实际发生的是page_1.jsp -> Action A -> Action B -> Action C -> Action C,即最后一个 Action 类被调用了两次。
page_1.jsp:
<button class="ink-button double-vertical-space all-25 dynamicButton"
id="finish" disabled> Finish </button>
[...]
$('#finish').click(function(event)
{
var fids = $('input:checkbox').filter(':checked').map(function ()
{
return this.id;
}).get();
$.ajax
({
method: "POST",
url: "A.action",
data: { fids : fids },
traditional: true,
success:
function()
{
// I know that the problem is here.
// Currently I have it like this, so it's understandable
// why action C is getting called 2 times,
// I just don't know how to fix it.
window.location = "C.action";
}
});
});
struts.xml:
<action name="A" class="action.A" method="execute">
<result name="success" type="redirectAction"> B </result>
</action>
<action name="B" class="action.B" method="execute">
<result name="success" type="redirectAction"> C </result>
</action>
<action name="C" class="action.C" method="execute">
<result name="success"> /page_2.jsp </result>
</action>
【问题讨论】:
-
删除该行就完成了。
-
$('#finish')是什么?提交? -
@RomanC:我已经尝试过了。如果我删除
window.location = "C.action",则正确调用动作(并且动作C只会被调用一次),但不会呈现page_2.jsp。 @DaveNewton:#finish是一个按钮,但不是提交按钮(我在 JSP 页面中没有表单):<button class="ink-button double-vertical-space all-25 dynamicButton" id="finish" disabled> Finish </button> -
@jaff 应该已经在第一次调用时渲染了。
标签: java ajax jsp struts2 action