Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make remeber me service

 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i am able to store cookie and retrieve it but the issue is i want to implement like remember me service. Once the user logs in then the next time he opens the browser he doesn't need to log in (most people implement remember my username and password service)
here is my code may i know what is wrong. I can store and access a cookie in the same browser session but wheni close and open my browser the cookie is not persent anymore.
For adding cookie code
Cookie cookie = new Cookie("cook","test") ;
cookie.setMaxAge(-1);

response.addCookie(cookie);
logger.debug("added the cookie...");

For retrieving cookie code


Any help on this will be much appreicated
Thanks
Rashid
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little more info would be good... how are you testing this? I mean, what client browser are you using, and how is it configured?

I once had a similar issue, and discovered that my Firefox browser was set to dump all cookies at end of session.

I recommend that you check your browser *during* the session to see if the cookie is being set as you expect, and then recheck in a new session to see if it has actually persisted the cookie.

Unfortunately, UBB doesn't allow me to show you the address bar javascript to reveal cookies in an alert dialog, but it isn't hard to figure out: its an alert with the document cookie object as the argument.

If you limit your detective work to the server-side, then you may be missing something simple.

If you aren't seeing what you expected, then check your browser's cookie acceptance policy.

Depending on the development tools that you have, you may also have an HTTP monitor available to you. Netbeans has one, and I'm pretty sure there is a similar function in Eclipse.

Hope this help!
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rashid Darvesh:
Hi
i am able to store cookie and retrieve it but the issue is i want to implement like remember me service. Once the user logs in then the next time he opens the browser he doesn't need to log in (most people implement remember my username and password service)
here is my code may i know what is wrong. I can store and access a cookie in the same browser session but wheni close and open my browser the cookie is not persent anymore.
For adding cookie code
Cookie cookie = new Cookie("cook","test") ;
cookie.setMaxAge(-1);

response.addCookie(cookie);
logger.debug("added the cookie...");

For retrieving cookie code


Any help on this will be much appreicated
Thanks
Rashid


The way you want to achieve this requirement is correct , but you have some wrong concepts regarding cookies.
You can set cookies with age as 5000 (using cookie.setMAxAge(5000)) , then the cookies will be written to the clients filesystem and each time the client requests for the same login page , the cookies are also sent to the server.With this you can find whether this user has already logged in successfully or not.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing is when you do a cookie.setMaxAge(-1) , the cookies dies as soon as you terminate your session.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its better to read Cookies JavaDoc to understand how to use methods to play around cookies.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
So the max age of a cookie can be the max value of the int type it can hold which is around 2,147,483,647

Rashid
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You always have control to provide custom headers, so you can just setup a response header set-cookie with cookie content which may have any age constraints.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic