tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: sessions and JSP Tag Handlers
Date Mon, 10 Jul 2000 17:48:52 GMT
Joel Regen wrote:

> "Craig R. McClanahan" wrote:
>
> > Joel Regen wrote:
> >
> > > After further research in the JSP spec (1.1) it appears that perhaps I should
be
> > > using beans and not tags.  Beans seem to be allowed to participate at various
scopes
> > > including session and application.    Tags, it appears, are not intended to
have
> > > scope beyond page.  Anyone want to concur (or not)?
> > > Joel
> > >
> >
> > It makes sense to think of the tags themselves as having page scope.  However, the
code
> > in a custom tag can easily reference beans in any scope (put there by a <jsp:useBean>
or
> > by some other mechanism).  For example:
> >
> >     MyObject object = pageContext.getAttribute("myKey",
> >         PageContext.SESSION_SCOPE);
> >
> > references a session attribute, using the implicit "pageContext" instance variable
that
> > is set by the TagSupport or BodyTagSupport class for you.
> >
> > Craig McClanahan
>
> What if, in a tag handler, I had code like:
>
>     pageContext.getSession().setAttribute( "foo", bar, PageContext.SESSION_SCOPE);
>
> and in another tag handler, referenced on another page I had:
>
>     pageContext.getSession().getAttribute( "foo", PageContext.SESSION_SCOPE);
>
> Would that be sufficient to create and access an object with session scope entirely within
> the tag handler semantics?
>

Actually, you should leave the getSession() thing out of these calls:

    pageContext.setAttribute("foo", bar, PageContext.SESSION_SCOPE);
    bar = pageContext.getAttribute("foo", PageContext.SESSION_SCOPE);

This is preferable to using the session object directly, because it assures synchronization
between the page context (for your tags) and the actual session attributes.

>
> Joel

Craig




Mime
View raw message