如何在将表单提交到第 3 方 URL 之前调用服务器端操作方法?
好的,我正在使用 Spring Webflow,目前有一个涉及两个 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">
<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) 最终第 3 方重定向回流程
6)在“接受”响应上,重新加载之前保存的模型对象
我想要做的是将两个jsp合并到一个视图中,并将这三种状态基本上压缩为一个。我有一些 javascript 和表单控件来将所有信息收集在一起。
问题是,我如何仍然将表单提交到第 3 方 URL,但在执行此操作之前,仍然在服务器端调用“creditAction.saveTrans(credit)”?显然,这需要对用户透明,他们应该对页面现在合并感到高兴,但仍然只需在最后单击“提交”,并在他们不知情的情况下完成所有后台保存和加载。
我想我可以在提交按钮上放置一个 onclick,使其只是一个普通按钮,然后从类似于以下内容的 javascript 提交表单,但是我如何调用我的服务器端代码来将模型保存在 .提交()?
function submitform() {
<!-- call creditAction.saveTrans(credit) somehow??? -->
document.forms["myform"].submit();
}
Ok, I'm using Spring Webflow and I currently have a flow that involves two jsp pages (views), the second of which submits a form to a 3rd party system (payments).
In my pay-flow.xml I have states such as these;
<!-- 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>
As you can see the process is basically like this;
1) Display 1st jsp, user enters some details, submits form
2) Save the model object to the database in the background
3) Display 2nd jsp, user enters more details and submits form
4) Form submits to a 3rd party URL, user interacts with 3rd party system
5) Eventually 3rd party redirects back into the flow
6) On "accepted" response, reload that previously saved model object
What I want to do is combine both jsps into one view and basically condense those three states into one. I've got some javascript and form controls to gather all the info together.
The question is, how can I still submit the form to the 3rd party URL but just before doing that, still call that "creditAction.saveTrans(credit)" on the server side? Obviously this needs to be transparent to the user, they should be happy the pages are now combined but still only have to click "Submit" at the end and have all the background saving and loading done without them knowing.
I was thinking I can put an onclick on the submit button, making it just a normal button and then submit the form from javascript similar to the following, but how can I call my server side code to save the model essentially on the line before .submit()?
function submitform() {
<!-- call creditAction.saveTrans(credit) somehow??? -->
document.forms["myform"].submit();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两种选择:
1)使用JavaScript更改表单的目标和操作并将其提交到隐藏的IFrame,提交,然后将其更改回正常状态并再次提交。
2)使用AJAX提交,然后正常提交表单。
You have two choices:
1) use JavaScript to change the target and action of the form and submit it to a hidden IFrame, submit, then change it back to normal and submit it again.
2) Submit it using AJAX, then submit the form normally.