Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

httprequest.getSession(false) creating a NEW Session

843841Mar 17 2006 — edited Apr 29 2009
I am working on a web application which uses STRUTS. All the client requests are directed to loginaction class.

Any resource in the application, is accessed thru the action class.

Overview: In the action class, i am checking if there is any session associated with the new user using
 session = request.getSession(false);
                  if (session != null) {
	 if (session.isNew()) {
	 logger.info("New Session Created [" + session.getId() + "]");
	 } else {
	 logger.info("Session EXIST'S ["+ session.getId()
	+ "], Retreiving user from session");
                   }
According to the Servlets 2.2 API:
public HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.

if (session.isNew()) ,
this if statement should return false and be skipped, as
session = request.getSession(false);
wont create a new session.
When i parse the logs, I see the log statement, "New Session Created ". Which makes me wonder, that a new session is being created


Problem: When i debug, i see that container is creating a new session if the session doesnt exist. According to API mentioned above, it should not create a new session. It should return null.


Did anyone had a similar issue? While researching i found this article that using struts, the container creates a default session.

I found this article: http://www.theserverside.com/discussions/thread.tss?thread_id=21643

Environment: IDE:WSAD5.1, Appserver:Websphere, Browser:IE 6.0, Struts, JSP, JSTL
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2009
Added on Mar 17 2006
13 comments
1,875 views