Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so does it mean that request.getSession() is just a wrapper on request.getSession(true);

mm, thanks!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
they are the overloaded methods with non-argument method calling the argumented method with default value
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic