简体   繁体   English

如何在javascript中存储表单数据以在其他页面或重新打开页面中使用历史记录

[英]How to store form data in javascript for history use in another page or reopen page

i want jsp or javascript for save form data for history -no cookies -no session -no database 我希望使用jsp或javascript保存历史记录的表单数据-无cookie-无会话-无数据库

when your open form, fill form, submit form... some time user have to come back on form for some change... all field of form with auto fill with old data...(because 28 fields in form) 当您打开表单,填写表单,提交表单...一段时间后,用户不得不返回表单进行一些更改...表单的所有字段均自动填充了旧数据...(因为表单中有28个字段)

If you are using HTML 5. You can employ HTML5's Local Storage. 如果您使用的是HTML 5,则可以使用HTML5的本地存储。

localStorage.setItem("name", "Hello World!"); //saves to the database, key/value
document.write(localStorage.getItem("name")); //Hello World!
localStorage.removeItem("name"); //deletes the matching item from the database

Then you can use HTML5. 然后,您可以使用HTML5。 Because there is a facility to store the temporally data and you can get that data into other pages also . 因为有一种存储时间数据的功能,所以您也可以将该数据存储到其他页面中。

Like this : 像这样 :

localStorage.setItem("key1", "Value1"); //saves to the database, key/value    
document.write(localStorage.getItem("key1")); //Will print value  of key1
localStorage.removeItem("key1"); //deletes the matching item from the database

You can´t track users/visitors without some kind of authentication and that might require sessions/cookies (and databases). 没有某种身份验证,您将无法跟踪用户/访问者,这可能需要会话/ cookie(和数据库)。

Closing the page/browser ends the session but cookies and localStorage are persistent. 关闭页面/浏览器会终止会话,但cookie和localStorage是持久的。

Serialize the form and the use localStorage to save it. 序列化表格,并使用localStorage保存它。

This is (as far as I am aware) not possible using browser history storage. 就我所知,这是无法使用浏览器历史记录存储的。 You would also not want it to be possible, as it means that other people using the same browser could use the back button to get to all of the user's possibly confidential data. 您也不想这样做,因为这意味着使用同一浏览器的其他人可以使用后退按钮来获取用户的所有可能的机密数据。

The right way to do this, if you really must, is to use cookies to keep track of the user's session and if they are logged in (and not otherwise), pre-fill the HTML of the form on the server with the information they entered into the database last time. 正确的方法(如果确实必须这样做)是使用cookie来跟踪用户的会话,并且如果它们已登录(而不是以其他方式登录),请在服务器上的表单HTML中预先填充它们的信息上次进入数据库。

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

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