HTML : LocalStorage and Session Storage

Introduction

We can save the data i the browser with these two techniques localStorage and SessionStorage

with LocalStorage data will be stored in the browser, even after browser is closed.

with SessionStorage once the browser is closed the data will be lost.

localStorage.setItem("mykey","myvalue");

localStorage.getItem("mykey");
localStorage.getItem("mykey");
localStorage.removeItem("mykey");
localStorage.clear();

SessionStorage

sessionStorage.setItem("mykey","myvalue");
sessionStorage.getItem("mykey");
sessionStorage.removeItem("mykey");
sessionStorage.clear();

var ourArray =[1,2,3,4,5];

localStorage.setItem("ourarraykey",JSON.stringify(ourArray));

sessionStorage.setItem("ourarraykey",JSON.stringify(ourArray));



var storedArray = localStorage.getItem("ourarraykey");
ourArray = JSON.parse(storedArray);

or, for sessionStorage:

var storedArray = sessionStorage.getItem("ourarraykey");
ourArray = JSON.parse(storedArray);

How to use the LocalStorage with JSP