944,080 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 2186
  • JSP RSS
Oct 31st, 2009
0

Session.isNew() problem

Expand Post »
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:

JSP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blindkilla is offline Offline
20 posts
since Oct 2007
Nov 1st, 2009
0
Re: Session.isNew() problem
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?
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,260 posts
since Dec 2007
Nov 2nd, 2009
0
Re: Session.isNew() problem
yeah I have tried running that first, however the problem has been solved. Thank you for posting.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blindkilla is offline Offline
20 posts
since Oct 2007
Nov 2nd, 2009
-1
Re: Session.isNew() problem
Problem was solved how? This can help someone in the future...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: How to redirect a page in JSP
Next Thread in JSP Forum Timeline: Help with GET method please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC