0

I have some login information; let's say user name, login email, and location.

I want keep this information in the browser even after the user logs out and closes the window.

When the user comes back after a logout or the session expiry, the web application fills the client user name and asks for the password from the user. The best example of my requirement is Google login.

Currently, I am using only session and no cookies.

What are the possible solutions?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Dileep
  • 5,362
  • 3
  • 22
  • 38

2 Answers2

2

I think you could use cookies for storing data on client side, follow this link

http://www.tutorialspoint.com/jsp/jsp_cookies_handling.htm

set storing age using the method public void setMaxAge(int expiry);

Also another solution is local storage in HTML5 but this is supported only in latest browsers.

http://www.w3schools.com/html/html5_webstorage.asp

http://diveintohtml5.info/storage.html

hope these links will help you

droidev
  • 7,352
  • 11
  • 62
  • 94
  • @user2310289 and what is the problem? This looks like to me as a valid answer. – LaurentG Mar 05 '14 at 05:35
  • 1
    The OP states that he knows about Cookies. He asks for other possible solutions. – Scary Wombat Mar 05 '14 at 05:38
  • @user2310289 what is the problem with using cookies ?.it is easiest and ethical method na ? – droidev Mar 05 '14 at 05:54
  • I have no problems with Cookie, but the OP is looking for another solution. Cookies was mentioned in the original question and in multiple comments since. So what is this answer adding? – Scary Wombat Mar 05 '14 at 05:57
  • @user2310289 OP is not saying he doesn't want cookies. he just states that he isn't using cookies. The question should be edited if cookies are not a valid answer. – LaurentG Mar 05 '14 at 07:08
  • I agrre that this answer should be edited, as the OP commented `cookies are one solution, but i am looking for another options ` – Scary Wombat Mar 05 '14 at 07:10
0

LocalStorage is considered to be the best solution for storing values permanently in the browser.!! A good explanation about the LocalStorage can be found here.

This is my code used to save the value to the LocalStorage.

         function saveLoginNameToLocalStorage()  
                {
                 if(typeof(Storage)!=="undefined")//checks whether the browser support localStorage
                  {
                        // you dont want to create a variable by var variablename, 
                        // just give it as localStorage.yourVariableName, before assigning 
                        // any values the variable is shown as  undefined.
                         if(localStorage.userName && localStorage.userName !="" && localStorage.userName==document.getElementById("userName").value){
                            document.getElementById("redirectUrl").value=localStorage.redirectURI;
                        }
                        else{
                            localStorage.redirectURI="";
                            document.getElementById("redirectUrl").value="";
                        }
                         localStorage.userName=document.getElementById("userName").value;
                         localStorage.redirectURI="";
                  } 
                }

You can access the variable using localStorage.userName from anywhere in the browser. Worked well for me. ;-)

Thanks everyone for the help provided..!!

Dileep
  • 5,362
  • 3
  • 22
  • 38