aspose file tools*
The moose likes Servlets and the fly likes session.isNew() is always returning false Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "session.isNew() is always returning false" Watch "session.isNew() is always returning false" New topic
Author

session.isNew() is always returning false

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
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

Joined: Mar 15, 2009
Posts: 453

have you referenced this servlet from a jsp???

avi sinha


SCJP 5.0 SCWCD 5.0
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
yes
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Oct 08, 2008
Posts: 492
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

Joined: Oct 08, 2008
Posts: 492
session.isNew() is always returning false
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

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
g raj
Greenhorn

Joined: Sep 25, 2007
Posts: 4
Hi avi sinha,

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

Regards,
Gandhi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: session.isNew() is always returning false