Java 如何在将表单提交到第三方url之前调用服务器端操作方法?
好的,我使用的是SpringWebFlow,目前我有一个包含两个jsp页面(视图)的流,第二个页面将表单提交给第三方系统(支付) 在我的pay-flow.xml中,我有如下状态:Java 如何在将表单提交到第三方url之前调用服务器端操作方法?,java,javascript,ajax,spring-mvc,spring-webflow,Java,Javascript,Ajax,Spring Mvc,Spring Webflow,好的,我使用的是SpringWebFlow,目前我有一个包含两个jsp页面(视图)的流,第二个页面将表单提交给第三方系统(支付) 在我的pay-flow.xml中,我有如下状态: <!-- Initial state, the jsp(view) gathers the number of items to purchase --> <view-state id="buy" view="credit/buy" model="credit"> <transit
<!-- Initial state, the jsp(view) gathers the number of items to purchase -->
<view-state id="buy" view="credit/buy" model="credit">
<transition on="submit" to="createTrans" />
</view-state>
<!-- State not tied to a jsp, saves the "credit" object to the database -->
<action-state id="createTrans">
<evaluate expression="creditAction.saveTrans(credit)"/>
<transition to="wpRedirect"/>
</action-state>
<!-- Gathers some more info & has a form that submits to the 3rd party system -->
<view-state id="wpRedirect" view="credit/redirect">
<transition on="accepted" to="showInvoice" history="invalidate">
<evaluate expression="creditAction.reloadTrans(credit)" result="credit" />
</transition>
</view-state>
正如你所看到的,这个过程基本上是这样的1) 显示第一个jsp,用户输入一些详细信息,提交表单
2) 将模型对象保存到后台数据库中
3) 显示第二个jsp,用户输入更多详细信息并提交表单
4) 表单提交到第三方URL,用户与第三方系统交互
5) 最终,第三方重新定向到流中
6) 在“已接受”响应中,重新加载先前保存的模型对象
我想做的是将两个JSP合并到一个视图中,并基本上将这三个状态压缩为一个。我有一些javascript和表单控件来收集所有信息 问题是,我如何仍然将表单提交到第三方URL,但在提交之前,仍然在服务器端称其为“creditAction.saveTrans(credit)”?显然,这需要对用户透明,他们应该很高兴现在合并了页面,但仍然只需在最后单击“提交”,并在他们不知道的情况下完成所有后台保存和加载 我想我可以在submit按钮上单击一次,使其成为一个普通按钮,然后从javascript提交表单,类似于下面的内容,但是我如何调用我的服务器端代码来将模型保存在前面的行中。submit()
函数submitform(){
document.forms[“myform”].submit();
}
您有两种选择:
1) 使用JavaScript更改表单的目标和操作,并将其提交到隐藏的IFrame、submit,然后将其更改回正常并再次提交
2) 使用AJAX提交表单,然后正常提交表单。您是否能够详细介绍选项2?我有类似Spring.addDecoration(newspring.AjaxEventDecoration)的东西({在其他一些页面中,虽然这些都是以前开发人员的遗留文件,所以我对它们的功能不太确定。网络上的大多数示例都是用于重新呈现页面片段,这不是我想要做的,我只需要执行一个方法,然后返回而没有结果?我不熟悉Spring框架,但是是的,您不需要返回值在通过AJAX提交表单时使用ue。成功执行调用是您所需要的。
function submitform() {
<!-- call creditAction.saveTrans(credit) somehow??? -->
document.forms["myform"].submit();
}