Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

request.getSession

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please validate the below scenarios are correct or not:

Scenario 1: When there is already an existing session

if request.getSession() is called ... container returns the pre-existing / current session.
if request.getSession(false)is called ... container returns the pre-existing / current session.

But if request.getSession(true) is called ... // What does it do?

Scenario 2: When there is no existing session

if request.getSession() is called ... container creates a new session and returns the reference back
if request.getSession(false)is called ... container returns NULL
if request.getSession(true) is called ... container creates a new session

 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hay amarkirt

request.getSession(true) is called ... // ontainer returns the pre-existing / current session.

HFSJ First Edition - page 233
 
Narendhiran Nagarajan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getSession() and request.getSession(true) are same.They will use the same sessionid if it exists or it will create a new sessionid.
In request.getSession(false) - it will use the same sessionid only if it exists, else it will return null as sessionid.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amarkirt saroay wrote:

But if request.getSession(true) is called ... // What does it do?



From my understanding , when there is a existing session request.getSession() and request.getSession(true) acts the same.
 
Narendhiran Nagarajan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For new or existing sessions, request.getSession() and request.getSession(true) always act same.
Its just another way of writing for our convenience.

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!