wood burning stoves 2.0*
The moose likes Servlets and the fly likes how to make remeber me service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to make remeber me service" Watch "how to make remeber me service" New topic
Author

how to make remeber me service

Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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

Joined: Oct 15, 2002
Posts: 189
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!


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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
LinkedIn - Blog
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Dec 06, 2005
Posts: 1321

its better to read Cookies JavaDoc to understand how to use methods to play around cookies.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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

Joined: Feb 07, 2004
Posts: 472

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.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make remeber me service
 
Similar Threads
Servlets-4b cookie question
please tell me when to use Session and Cookie?
IE6 - Remove cookies using java or javascript
Can't read cookie from another page!
New to cookies