Originally posted by deepa raj:
for the very first request , session will not be created.
so req.getSession(false) will return null.
I guess it should throw NullPointerException.is it so?
Please corretc me if i am wrong.
You got to really understand the various scopes available.
The biggest of them is context(application), then comes session, and then the request scope. (although there is another scope as page scope, but we are not disussion scoping here)
Thus, to have a request object you got to have the two upper level objects available.
So, when you say request.get(.....) then session scope is by default available.
As a very raw example consider that when a user(consider it the very first user) opens a browser and hits the url for an application in a web container the context is initialized. Then the session is created for that user which you may consider as the time his browser is active, unless session expiry is set. Then whatever he queries with the container is all request..
But, again a gotcha is there might be no active session at the time you do the query. So, in that case what you say is inherently true..
Hope that helps.
[ August 06, 2008: Message edited by: Anubhav Anand ]