• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to make remeber me service

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic