| | |
Session.isNew() problem
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2007
Posts: 18
Reputation:
Solved Threads: 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:
It never gets into that if statement because it always returns false
Any help would be appreciated.
I'm trying to do the following in my servlet:
JSP Syntax (Toggle Plain Text)
HttpSession session = request.getSession(true); if (session.isNew()) { ...do something... }
It never gets into that if statement because it always returns false

Any help would be appreciated.
0
#2 Nov 1st, 2009
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?
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?
Check out my New Bike at my Public Profile at the "About Me" tab
-1
#4 Nov 2nd, 2009
Problem was solved how? This can help someone in the future...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Other Threads in the JSP Forum
- Previous Thread: How to redirect a page in JSP
- Next Thread: Help with GET method please
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






