On Sat, 17 Aug 2002, Nikola Milutinovic wrote:

> Date: Sat, 17 Aug 2002 16:23:31 +0200
> From: Nikola Milutinovic <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: Re: retrieving HttpSession in Filter?
>
> Craig R. McClanahan wrote:
>
> >
> > This is not the right test for a newly created session, because there
> > *was* no requested session.  Try something like this instead:
> >
> >   HttpSession session = request.getSession(false);
> >   if (session == null) {
> >     ... no session exists ...
> >   } else if (session.isNew()) {
> >     ... this is a newly created session ...
> >   } else {
> >     ... this is an existing session ...
> >   }
>
> Hi Craig.
>

THe answers to all of these questions are in the servlet API javadocs --
among other places, you can get them in the servlet spec:

  http://java.sun.com/products/servlet/download.html

> One quick question. What are the semantics of "session.isNew()"?
>

This returns true if the client has not acknowledged that they want to
participate in this session yet -- in other words, from the moment the
session is created until the client returns a subsequent request with the
session id, that session is considered "new".

> If I call request.getSession(false), can it fail (return "null")? What would
> that mean?
>

Returning null is not a failure -- it means that there was no session
already in existence.

request.getSession(true)  - Create (if necessary) and return a session
request.getSession(false) - Return a session if there is one, but don't
                            create a new one
request.getSession()      - Same as request.getSession(true)

> I realize it should return "null" inside a JSP page that had page session
> setting turnet to "false", but in general, is there any other occasion?
>

Reading the API javadocs, and the servlet spec, will tell you a lot about
the environment you are trying to program for :-).

> Nix.
>

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to