简体   繁体   English

保留以前的表格数据

[英]Retaining previous form data

I have a form that I could put on to one page, but for aesthetic reasons, I want to split into two. 我有可以放在一页上的表格,但是出于审美原因,我想分成两部分。 The original form, on submission, would go to a Servlet which would get the form data and insert it into a database. 提交后,原始表单将转到Servlet,该Servlet将获取表单数据并将其插入数据库中。 However, I don't know how to make this work when it is split into two different forms on two different pages. 但是,当它在两个不同的页面上分成两种不同的形式时,我不知道如何使它起作用。 My forms are currently in html but I could change them to JSP if that is the solution. 我的表单当前使用的是html,但如果可以的话,可以将其更改为JSP。 I do not want to use hidden fields; 我不想使用隐藏字段; if there is no way to do it without hidden fields, then I will just put it on one page as my form has quite a few fields and hidden fields would mean basically doubling the amount of code. 如果没有隐藏字段就无法做到这一点,那么我将其放在一页上,因为我的表单中有很多字段,而隐藏字段意味着基本上将代码量加倍。 I also only want to use html or jsp for the forms; 我也只想对表单使用html或jsp; I don't want to use JavaBeans, and I want to avoid scripting in the jsp's. 我不想使用JavaBeans,并且希望避免在jsp脚本中使用脚本。 I have already done this by simply dividing the database logic into two and using the ID of the last inserted object as a hidden field, and the second form then uses that ID to update that item, but this is not an elegant solution and could cause a problem if one user submitted the first form and a different user submitted the second (the wrong item would be updated). 我已经通过将数据库逻辑一分为二并使用最后插入的对象的ID作为隐藏字段来完成此操作,然后第二种形式使用该ID来更新该项目,但这不是一个很好的解决方案,并且可能导致如果一个用户提交了第一个表单,而另一个用户提交了第二个表单,则会出现问题(错误的项目将被更新)。 Is this possible? 这可能吗?

好的,这是Session可以用来做的事情之一:将第一页中的数据存储在HttpSession中,然后在第二页中检索会话数据并将其保存到数据库中。

  1. You can use javascript pagination (It'll save page loading time. Many online test applications adopt this approach) a) Either on submission on each part of form data will send to server using ajax call.(partial submission) b) Or the whole data will be maintained at client side only until whole form is completed and submitted successfully. 您可以使用javascript分页(这可以节省页面加载时间。许多在线测试应用程序都采用这种方法)a)在表单数据的每个部分提交时,都将使用ajax调用发送到服务器。(部分提交)b)或整个数据将仅在客户端维护,直到完整填写表格并成功提交。 (depends on your application need) (取决于您的应用程序需求)

  2. You can logically relate each part of form with some unique id & session id combination. 您可以在逻辑上将表单的每个部分与某些唯一的ID和会话ID组合相关联。 In addition, if you are not willing/required to store whole form data in session, you can have primary key in session. 另外,如果您不愿意/不需要在会话中存储整个表单数据,则可以在会话中使用主键。 It'll make database update process easier for 2nd or next part of form data. 这将使表单数据的第二部分或下一部分的数据库更新过程更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM