我可以在 HTML 页面上的表单之间共享数据吗?或者可以先提交一份表格,再提交另一份表格吗?

发布于 2024-11-06 17:41:57 字数 769 浏览 0 评论 0原文

我想知道是否有人可以提供建议?我有一个 JSP,其中包含两个表单,这两个表单都映射到服务器上的同一个 servlet。

一切看起来都很好,尽管当我提交一个表单时,在另一个表单上输入的必要数据并未同时提交。

第一个表单用于添加或删除 RSS 提要的地址。由于页面上可能有多个地址,因此使用表来存储它们。表的每个单元格都包含一个用于删除的表单,如下所示:

<form action = "<c:url value = '/deleteRSSFeed?rssFeedURL=${rssFeedURL}' />" method = "post">                           
<input type = "image" src = "${imageFileURL}myApp_rightArrow.png" />                            
<input name = "writeWordcloud" type = "hidden" value = "true" />
</form>

还有另一个用于添加提要的表单。

情况是,提交这些表单中的任何一个后,都必须在页面上重新绘制词云。但词云的设置包含在另一种形式中。

由于我无法合并表单,谁能告诉我是否可以在 HTML 格式的表单之间共享数据?或者更好的是,是否可以提交一个表单,然后让此操作提交第二个表单?

此时,让不同的 servlet 提供表单对我来说是不切实际的。

谢谢

摩根先生

I wonder if anyone can advise? I have a JSP which contains two forms, both of which are mapped to the same servlet on the server.

Everything seems fine although when I submit one form, a necessary piece of data entered on the other form is not being submitted at the same time.

The first form is used to add or delete the address of an RSS feed. As there may be several addresses on the page, a table is used to store them. Each cell of the table contains a form like this for deletion:

<form action = "<c:url value = '/deleteRSSFeed?rssFeedURL=${rssFeedURL}' />" method = "post">                           
<input type = "image" src = "${imageFileURL}myApp_rightArrow.png" />                            
<input name = "writeWordcloud" type = "hidden" value = "true" />
</form>

And there is another form for adding a feed.

The situation is that upon submission of either of these forms, a wordcloud must be redrawn on the page. But the wordcloud's settings are contained in the other form.

As it not possible for me to merge the forms, can anyone tell me if I can share data betwen forms in HTML? Or better yet, is it possible to submit one form, and have this action submit the second form?

At this point, it is not practical for me to have the forms served by different servlets.

Thanks

Mr Morgan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

油焖大侠 2024-11-13 17:41:57

通过使用 Javascript(或者更好的是 jQuery),您可以让一个表单中的隐藏字段在提交之前获取另一个表单的字段值。

更新

此小提琴显示您需要的代码:http://jsfiddle.net/MqsK8/ 1/

By using Javascript (or better, jQuery), you can have hidden fields in one form get the other form's fields values before submitting.

Update

This fiddle shows the code you need: http://jsfiddle.net/MqsK8/1/

懷念過去 2024-11-13 17:41:57

您可能应该使用单一表单,并让服务器端脚本执行这两个操作。
根据您的场景,您可能需要两个提交按钮来执行不同的任务;服务器可以检查单击了哪个按钮。

You should probably use a single form, and have the server-side script perform both actions.
Depending on your scenario, you may want to have two submit buttons for different tasks; the server can check which button was clicked.

去了角落 2024-11-13 17:41:57

如果您能提供您正在尝试做的事情的详细信息,那就太好了。您可以使用 Javascript 将元素添加到 DOM,但所有这一切都取决于您的用例。

It would if you can provide detail of what you are trying to do. You can use Javascript to add elements to DOM but again all of this will depend on your use-case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文