当您单击一个表单中的“提交”时,如何从jsp页面中的两个表单发送数据
在我的项目中,我有一个这样的场景,如果我单击jsp中的提交,该jsp有两个表单,我已将数据从两个表单发送到目的地,我该怎么做,请帮助我。
In my project i have a scenario like this if i click submit in a jsp which has two forms i have send data from two forms to destination,how can i do that,Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的意思是要在同一请求中发送两个表单中的数据,则这是不可能的。
您必须将数据从一种表单复制到另一种表单,或者从两种表单复制到新表单。
您可以将隐藏字段放入表单中,以获取需要复制到其中的值。
If you mean that you want to send the data from the two forms in the same request, that is not possible.
You would have to copy the data, either from one form to the other, or from both forms into a new form.
You can put hidden fields in a form for the values that you need to copy to it.
我认为你可以做到这一点的唯一方法是完全绕过 FORM- 机制。您可以在提交按钮上放置一个
onclick()
javascript 事件,该事件调用一个 javascript 函数,您可以调用sendAll()
或其他函数。在此函数中,您可以获取所有表单字段和值,然后发送包含所有值的
XMLHttpRequest
(这是 ajax 请求的基础)。这确实很复杂,但在我看来,这是唯一可行的方法。
The only way i think you can do this is completely bypassing the FORM- mechanism. You could put an
onclick()
javascript event on the submit buttons which calls a javascript function you could callsendAll()
or something.In this function you could get all your formfields and values and then send an
XMLHttpRequest
(this is the basic of an ajax request) with all that values in it.That is indeed complicated but it seems to me that this is the only way it could work.