According to http://java.sun.com/products/servlet/2.3/javadoc/index.html
It looks like getSession() and getSession(true) do the same thing.
getSession(true) does not
create a new session if one already exists.
getSession
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.
To make sure the session is properly maintained, you must call
this method before the response is committed. If
the container is using cookies to maintain session integrity and
is asked to create a new session when the
response is committed, an IllegalStateException is thrown.
Parameters:
true - to create a new session for this request if
necessary; false to return null if there's no current
session
Returns:
the HttpSession associated with this request or null if
create is false and the request has no valid
session
See Also:
getSession()
--
getSession
public HttpSession getSession()
Returns the current session associated with this request, or if
the request does not have a session, creates one.
Returns:
the HttpSession associated with this request
See Also:
getSession(boolean)
Michael Sloan
|-+>
| ||
|-+>
>--|
|
|
| To:
|
| cc:
|
| Subject:
|
>--|
Well,
in fact there are three ways to use getSession(), a 'default' one
plus a method that takes a boolean as input indicating whether
to explicitly create a Session or not. Normally, one would use
the default implementation (getSession()). This will either return
a reference to the Session if one already exists, _or_ create a
new one and return a reference to that (lic: Singleton pattern).
In both cases, after calling getSession(), a valid Session instance
should exist. If you pass an additional boolean parameter to
this (overloaded) method, you can control session creation
behavior on your own. So if you just want to check if a request
already belongs to a Session, you pass 'false' and then check
for null being returned (or the other way round). If you want
a new Session to be explicitly created each time, you pass
'true'. You can easily get these details from the API docs,
just to note.
HTH,
-- Chris (SCPJ2)
NB. I said I never tried, but looking for JSESSIONID (still
wonder if this is correct, could be some '_' goes some-
where; but then, I might be mixing this up with form-based
login) would be my first approach for session-enabling
the GUI thing. Thought I made that somewhat clear
before. Didn't I?
> -Original Message-
> From: A mailing list about Java Server Pages specification
> and reference [mailto:[EMAIL PROTECTED]] On Behalf Of
> Evan Wright, iLabs Inc.
> Sent: Tuesday, February 04, 2003 11:39 AM
> To: [EMAIL PROTECTED]
> Subject: Re: HttpClient to Servlet
>
>
> Create a session object the first time the client connects
> (log in) with
> getSession(true) and each subsequent getSession(false) would
> return that
> object. (?)
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.
==