You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by A Yang <ay...@yahoo.ca> on 2001/02/17 00:05:09 UTC

Question about sessions

If I instantiate a javabean from a JSP: 

<jsp:useBean id="myBean" class="com.mycorp.somebean"
scope="session">
<jsp:setProperty name="myBean" property="*"/>
</jsp:useBean>

and hand off control to a servlet where I retrieve the
session using:

HttpSession session = req.getSession(false);

Shouldn't session.isNew() return "false" because the
session already exists?

Thanks and regards,
Andy



_______________________________________________________
Do You Yahoo!?
Get your free @yahoo.ca address at http://mail.yahoo.ca

Re: Question about sessions

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
A Yang wrote:

> If I instantiate a javabean from a JSP:
>
> <jsp:useBean id="myBean" class="com.mycorp.somebean"
> scope="session">
> <jsp:setProperty name="myBean" property="*"/>
> </jsp:useBean>
>
> and hand off control to a servlet where I retrieve the
> session using:
>
> HttpSession session = req.getSession(false);
>
> Shouldn't session.isNew() return "false" because the
> session already exists?
>

It depends on how you do your handoff.

If you use <jsp:forward> (or RequestDIspatcher.forward()) in the context
of the same request, the client does not know about it yet.  No response
containing the session ID (as a cookie or a rewritten hyperlink) has ever
been transmitted, and the client has never said "i am part of session
XYZ", so by definition the session is still considered "new".

If you use a sendRedirect(), or wait for a subsequent request, the
servlet container will see that the session is already in existence and
isNew will be false.  Among other things, this means that the client has
positively acknowledged that they are participating in this session (by
returning the session ID on the subsequent request).

>
> Thanks and regards,
> Andy
>

Craig McClanahan


>
> _______________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.ca address at http://mail.yahoo.ca
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org


RE: Question about sessions

Posted by George McKInney <ge...@tantalus.com>.
> -----Original Message-----
> From: A Yang [mailto:ayang_ml@yahoo.ca]
> Sent: Friday, February 16, 2001 3:05 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Question about sessions
>
>
> If I instantiate a javabean from a JSP:
>
> <jsp:useBean id="myBean" class="com.mycorp.somebean"
> scope="session">
> <jsp:setProperty name="myBean" property="*"/>
> </jsp:useBean>
>
> and hand off control to a servlet where I retrieve the
> session using:
>
> HttpSession session = req.getSession(false);
>
> Shouldn't session.isNew() return "false" because the
> session already exists?
>

I don't think so, IF the client hasn't yet seen the session. I think it only
returns false if the request includes the session ID, which it won't until
there has been a round-trip back to the client.

George McKinney, Developer
tantalus communications inc.
500-1122 Mainland Street
Vancouver, BC, Canada V6B 5L1
george@tantalus.com

Direct  604.726.6753
Main    604.609.0700
Fax     604.609.0705
www.tantalus.com
"When eBusiness experience counts."