Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I understand the difference between request.getSession(true) and request.getSession(false). But request.getSession() & request.getSession(true) look very similar!

Both "return the current session associated with this request", but differ in:

request.getSession():

"or if the request does not have a session, creates one"

request.getSession(true):

"if there is no current session, returns a new session"

I don't understand the difference between them, is it that (if none exists) they create a new session but the first one doesn't return it but the second one does?

Source: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

Edit:

Someone tagged/marked my question as duplicate even though it isn't. I will explain why.

I have explicitly asked for the difference between request.getSession() & request.getSession(true) and NOT between request.getSession(true) & request.getSession(false)! I have stated , again explicitly, that I already understand the difference b/w ..(true) & ..(false).

The question linked as a possible duplicated of of asks about the difference b/w ..(true) & ..(false) and not ..(true) & ..()

question from:https://stackoverflow.com/questions/30980616/difference-between-request-getsession-and-request-getsessiontrue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
106 views
Welcome To Ask or Share your Answers For Others

1 Answer

request.getSession() is just a convenience method. It does exactly the same as request.getSession(true).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...