Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Session.isNew()

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have this code in a servlet



i undertand that getSession() and getSession(true) will create a session if already not present and return the one if present and getSession(false) will return if session already exists and null if not.

The server for the very first request will append the sessionId both in URL and cookie and later depending up on clients settings either on theURL or cookie only.

But when i ran this code for the very first time it behaved orrectly.isNew() returned true but later when i killed the session through invalidate and restarted the server,cleared the cookies and ran the servlet now once again the isNew() should return true instead it is always returning false.that means the session already exists what actually is happening here.

Thanks
 
Devendra Joshi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try getting the cookie in the servlet and printing it. If you can get the cookie then probably you are not properly cleaning up the cookie on the client.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes I am able to get the session cookie in my forwarded servlet. but i have cleared the private data selecting cookies.

Thanks
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raja,
which browser are you using.
I think the cookie is not getting cleared in this case..
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Mozilla

Thanks
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the following line to your Servlet. Seeing if the ID is really the same is important in isolating the issue.

It's possible that a new session is getting created by a JSP after the first session has been invalidated. JSPs always participate in a session (and thus also create a new one) unless they contain a page directive with session="false".
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I added getID() in to my servlet and first i tried with Mozilla i got isNew() false and ID as 62B7411E75C79720CF89C617FEDD5866
again i opened IE 6.0 cleared all the cokies and private data once again i got isNew() false and ID as ADC7C04E309AC4717804A5130A5C4EF9

different session id but isNew() false. I think two seperate sessions are created but isNew() always returns false and i am using servlet and not the Jsp only first screen to invoke a servlet is JSP both creating of session and retriving it from cookies are also in servlet.

Am i missing any thing here.

Thanks
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Any updates on this issue.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic