Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Still confused about why method for preExisting session?

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ purpose of having getSeesion(false) is given as <b>"You might have a scenario in which a servlet wants to use only a previously created session.It might not make sense for the checkout servlet,for example,to start a new session."</b> I was confused here because ,getSession() already takes care of creating new session only if it doesn't exist.!!! We don't have to check for it by using getSessin(false) method.

I didn't read filters yet.May be I will understan then??!!.

I posted this question in other thread where ranchers have answered.But I didn't explain well there.Here is that thread if you want to have lok at it.

Thanks
Veena
 
C Chavan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the book says, request.getSession(false) is used in situation where current request MUST be associated with an existing session. This might be necessary in situation where you want to do a multi-step process (e.g. wizard like process, checkout process etc) and want to make sure everything happens within one session boundary. request.getSession(false) helps ensure that.

if you call request.getSession() or request.getSession(true), it will always return Session object, existing or new.
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.In other words getSession(false) can be thought of shortcut for following code ?



Thanks again for the reply.
Veena
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

if you'd like a alias code gor getSession(false), one could say this :



getSession(false) retrieves the pre-existing session if it exists, otherwise it returns null.

If you access a check out page of an online store with no session, it means you didn't order anything so no need to process anything. In this case, getSession(false) returns null and you know immediatly no order is placed so no payment is to be made.
[ March 07, 2006: Message edited by: Frederic Esnault ]
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think following is better.

if (request.isRequestedSessionIdValid()) { session = getSession(); }

Thanks
[ March 08, 2006: Message edited by: Narendra Dhande ]
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.I got to know more than I wanted to know about method getSession(false)

Thanks for the info.
Veena
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic