Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getSession() vs request.getSession(boolean create)

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing these lines from Java API



I am unable to understand the difference between 2. getSession() create a session if there is no session exist and getSession(boolean create) also creates a session if there is no session (if we pass TRUE). If the later function can perform the same functionalities then why the prior function is needed? or i am mis-interpreting the meanings and purpose of both function. Please explain out!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getSession(false) will not return a new Session if one does not already exist.

If your application needs to explicitly create and initialise a session, or you decide to use the existence of a session as detection of a logged in user, then you don't want to create sessions by accident. It is also useful as it can tell you where a user entered your application, ie if session==null then they didn't request another page before this one.
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so does it mean that request.getSession() is just a wrapper on request.getSession(true);

mm, thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The implementation is up to the container builders but it seems like a pretty safe bet that that's how they do it.
If you really want to know, you can always grab the source to Tomcat, Jetty, Resin, or any other open source container and see for yourself.
[ July 24, 2007: Message edited by: Ben Souther ]
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are the overloaded methods with non-argument method calling the argumented method with default value
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic