Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes cookie vs session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "cookie vs session" Watch "cookie vs session" New topic
Author

cookie vs session

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
Hi folks,

I'm a little bit confused when it comes to using 0 or -1 with setMaxInactiveInterval for the session and setMaxAge for the cookie.

Here is what I mean

1 - What invalidates the session automatically ?
setMaxInactiveInterval(0) or setMaxInactiveInterval(-1)

2 - What makes the cookie disapears automatically when the users exits
setMaxAge(0) or setMaxAge(-1) ?

thanks


SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
--------------------
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
Phillipe Eduardo Lemos
Greenhorn

Joined: Aug 10, 2007
Posts: 7
Hi Mamadou Tour�


The method setMaxInactiveInterval set the time in seconds between the clients requests before sevlet container invalidate the session. The negative values indicate that session will never timeout. If you want to invalidate the session it has two possibilities
a) call invalidate method of HttpSession.
b) set setMaxInactiveInterval to zero.

The method setMaxAge set the maximum age of cookie in seconds. The positive values indicate that the cookie will expire after that many seconds have passed. The negative value means that the cookie
it's not stored persistently and will be deleted when the browser exits. If the value is zero the cookie will delete.
(see http://java.sun.com/j2ee/1.4/docs/api/index.html)

Regards
Phillipe Lemos
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cookie vs session
 
Similar Threads
setMaxInactiveInterval and <session-timeout> question
Why session destroyed when browser closed
setMaxInactiveInterval and setMaxAge ?
Doubt between setMaxAge() and setMaxInactiveInterval() method
session that never dies