Session.isNew() problem

Reply

Join Date: Oct 2007
Posts: 18
Reputation: blindkilla is an unknown quantity at this point 
Solved Threads: 0
blindkilla blindkilla is offline Offline
Newbie Poster

Session.isNew() problem

 
0
  #1
Oct 31st, 2009
When my servlet creates a session, even if it is the first time running the servlet, the session.isNew() returns false. I checked to make sure the session ID's are different each time I run it and they are, yet isNew() still returns false.

I'm trying to do the following in my servlet:

  1. HttpSession session = request.getSession(true);
  2. if (session.isNew())
  3. {
  4. ...do something...
  5. }

It never gets into that if statement because it always returns false

Any help would be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,713
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #2
Nov 1st, 2009
First of all when you have questions such as this, always search the API.

http://java.sun.com/javaee/5/docs/ap...n.html#isNew()

http://java.sun.com/j2ee/sdk_1.3/tec...ssion(boolean)

From the create session method, you see that it doesn't always create a new session. That call is the same as the no argument getSession() . The only difference is when you enter false. Then if there is no session it returns null.
But if you put true, it will not create a new session if one already exists.

I know that the above might no solve your problem because I just quoted the API, but have you tried running the session.invalidate() method first?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 18
Reputation: blindkilla is an unknown quantity at this point 
Solved Threads: 0
blindkilla blindkilla is offline Offline
Newbie Poster
 
0
  #3
Nov 2nd, 2009
yeah I have tried running that first, however the problem has been solved. Thank you for posting.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,252
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer
 
-1
  #4
Nov 2nd, 2009
Problem was solved how? This can help someone in the future...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the JSP Forum
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC