*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes setMaxInactiveInterval and <session-timeout> question 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 "setMaxInactiveInterval and <session-timeout> question" Watch "setMaxInactiveInterval and <session-timeout> question" New topic
Author

setMaxInactiveInterval and <session-timeout> question

Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
are the following four the same ?






** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
Found a potential incorrect note in FREDERIC ESNAULT's revision notes

he said in setMaxInactiveInterval() , -1 works like invalidate()

but the offical API said A negative time indicates the session should never timeout.

why??
swapnl patil
Ranch Hand

Joined: Aug 13, 2007
Posts: 80
setMaxInactiveInterval() takes time in second and web.xml we specify the time in minute.

then think on it. Read Head first for Servlet & JSP Session management chapter for more clarification .
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Session
setMaxInactiveInterval(0) == invalidate()
setMaxInactiveInterval(-1) == session will never expire

Cookie
setMaxAge(0) == cookie is invalidated
setMaxAge(-1) == cookie is valid till browser closing

SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
Lucas Smith wrote:Session
setMaxInactiveInterval(0) == invalidate()
setMaxInactiveInterval(-1) == session will never expire

Cookie
setMaxAge(0) == cookie is invalidated
setMaxAge(-1) == cookie is valid till browser closing


what if i set the "time-out" in DD to the value of -1?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

From the servlet spec about <session-timeout>
If the timeout is 0 or less, the container ensures the default behavior of sessions is never to time out.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
Ankit Garg wrote:From the servlet spec about <session-timeout>
If the timeout is 0 or less, the container ensures the default behavior of sessions is never to time out.

Thanks
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

It's misleading.
setMaxInactiveInterval(0) -> invalidate()
<session-timeout>0</session-timeout> -> never invalidate
warunyou rattanabuangam
Greenhorn

Joined: Jul 20, 2011
Posts: 1
Lucas Smith wrote:Session
setMaxInactiveInterval(0) == invalidate()
setMaxInactiveInterval(-1) == session will never expire

Cookie
setMaxAge(0) == cookie is invalidated
setMaxAge(-1) == cookie is valid till browser closing


thank you.
Cristian Daniel Ortiz Cuellar
Ranch Hand

Joined: Feb 02, 2011
Posts: 81
warunyou rattanabuangam wrote:
Lucas Smith wrote:Session
setMaxInactiveInterval(0) == invalidate()
setMaxInactiveInterval(-1) == session will never expire

Cookie
setMaxAge(0) == cookie is invalidated
setMaxAge(-1) == cookie is valid till browser closing


thank you.


if i make request.getSession(false).setMaxInactiveInterval(0); the session will never expire..

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1624
    
  23

have a look at this thread for more about his subject.

Regards,
Frits
 
Don't get me started about those stupid light bulbs.
 
subject: setMaxInactiveInterval and <session-timeout> question
 
Similar Threads
How to use different session timeouts for different levels of users
session. setMaxInactiveIntervel()
session is not invalidating
2 Inconsistencies in session-timeout and setMaxInactiveinterval
session that never dies