0

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:

HttpSession session = request.getSession(true);
if (session.isNew())
{
                ...do something...
}

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

Any help would be appreciated.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by peter_budo
0

First of all when you have questions such as this, always search the API.

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html#isNew()

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html#getSession(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?

0

yeah I have tried running that first, however the problem has been solved. Thank you for posting.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.