Session

What's the difference between getSession(true) and getSession(false)?
[84 byte] By [sraa_rpva] at [2007-10-3 2:28:38]
# 1
JavaDocs are a good place to find this type of information: http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html
tolmanka at 2007-7-14 19:27:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
but according to that it getSession(false) should return null. but it returns session. then that is the purpose of that. when should we go for getSession(true) and getSession(false)
sraa_rpva at 2007-7-14 19:27:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

as stated above, from the API it says

Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

If create is false and the request has no valid HttpSession, this method returns null

Therefore, if you call getSession(false) and the session currently exists within the SessionManager and has not timedout, it will return the session. If it does not exist, or has timedout it will return null.

getSession(true) will return a session regardless. Therefore if the session has expired it will return a NEW session.

thanks

codemwnci.

codemwncia at 2007-7-14 19:27:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...