Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.isNew() is always returning false

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I just tried with a small servlet test.

In the servlet



Am always getting old session value. I tried with clearing cookies and restarted tomcat. Some times am getting new session Id and session creation time. Please assist me

I tried in IE
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you referenced this servlet from a jsp???

avi sinha
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in jsp session is created by default. when your request reaches the servlet the session has already been created.

in jsp write :


and you will get the desired behaviour.

avi sinha
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isNew returns true the first time the server sees the user, and you are assuming that te first time the server sees the user, your code is being run.
I am not sure about the specifics of your application, but this obviously isn't true.
Rather than getting bogged down in the behaviour of a single method, have you tried reading a session value and then writing it if the value does not yet exist?

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
avi sinha wrote:in jsp session is created by default. when your request reaches the servlet the session has already been created.

in jsp write :


and you will get the desired behaviour.

avi sinha



Hi Avi.. I tried with this evan after restarting the server same issue.. Always old session value
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.isNew() is always returning false
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meet Gaurav wrote:session.isNew() is always returning false


open the jsp page in your browser and check the cookies . if a cookie JSESSIONID id there for your host then the problem is in your jsp not in the servlet.

avi sinha
 
N.Gandhi Rajan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi avi sinha,

It might be an old post. But was really helpful and you made my day... thanks a lot

Regards,
Gandhi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic