It's not a secret anymore!
The moose likes Servlets and the fly likes Session Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Creation" Watch "Session Creation" New topic

Session Creation

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
I've got a test web app going in which I do not call request.getSession() in any servlets, jsps, tags, etc.. However, I do call request.getSession(false). To my surprise, the latter call returned a Session object; I had expected null.

Can anyone pls explain why a session was created for me w/o my ever having explicitly requested that one be created?

Fun programming etcetera!
Hongli Li
Ranch Hand

Joined: Oct 29, 2006
Posts: 124
do you use Struts in your application, if so, struts automatically creat a locale attritue and store it into a session. why do not you try to print out all the session variables, and see what's inside that session?
[ January 07, 2007: Message edited by: Hongli Li ]

Do you know why this cup is useful? Because it is empty.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Create an HttpSessionListener with a sessionCreated() method that dumps the stacktrace and whatever is in the Session.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

JSPs, unless you specifically disable them with session="false" in the page directive will create a session for you automatically.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Ah, thanks. I forgot that if JSPs have an implicit reference to a session object, then a session object must have been created.
I agree. Here's the link:
subject: Session Creation
It's not a secret anymore!