• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Differnce between 2 sessions..

 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the differnce between


request.getSession(true);
request.getSession(false);

Also, In what situations they are used.

Regards..
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getSession(true)
request.getSession(false)

The signature of this method is
HttpSession getSession(boolean create)

Now if you pass true that means boolean create = true, this means to create a new session if doesnot exist

but if you pass false that means not to create a session , return the existing session if already exist or return null.

request.getSession(true) and request.getSession() will give same results.
 
Karne Reddy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of JSP page

request.getSession(true) or request.getSession(false) or

request.getSession().

All are equal. U wont get null for request.getSession(false)



Ashok Reddy K
 
Prakash Kumbhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If <%@ page session="false" %> is presnt then
request.getSession(true) will create new session if it does not exist
and request.getSession(false) will return null if session is not present.
 
Prakash Kumbhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If <%@ page session="false" %> is presnt then
request.getSession(true) will create new session if it does not exist
and request.getSession(false) will return null if session is not present.
 
Karne Reddy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prabhu,

When i include the following thing in JSP

<%

session.invalidate();
request.getSession(false).setAttribute("name","Test"); //2


%>

request.getSession(false) is returning null?

I know we r invalidation the session. But it shud create a new session know
if not existed?



???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic