This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpServletRequest getSession methods

 
Daniel Wendhausen
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Tim Moores
Saloon Keeper
Posts: 3266
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To save you from having to type the 4 letters t-r-u-e.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!