• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpServletRequest getSession methods

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy ranchers,

Im currently studying for SCWCD certification and i just faced on doubt.
Whats the difference between getSession() and getSession(true)

from Oracle specification:
http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getSession%28boolean%29

Since both returns the current HttpSession associated with the request or, if there is no current session, returns a new session.
If they do same thing, whats the point of having both?

Thanks,
Daniel
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The getSession() is same as getSession(false). That means you don't get any session if it does not exist before getSession() is called.
Whereas getSession(true) always returns a session, either the existing one or a new one if none exists.

Hope this helps
 
Daniel Wendhausen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Ghorpade wrote:The getSession() is same as getSession(false). That means you don't get any session if it does not exist before getSession() is called.
Whereas getSession(true) always returns a session, either the existing one or a new one if none exists.

Hope this helps



In the link i can see:
"HttpSession getSession() = Returns the current session associated with this request, or if the request does not have a session, creates one."

As far i understand getSession() its the same as getSession(true), and not getSession(false), right?
So, i was wondering why have both methods, if getSession(boolean x) alread satisty both situations.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To save you from having to type the 4 letters t-r-u-e.
 
reply
    Bookmark Topic Watch Topic
  • New Topic