tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Regen <j...@Globeset.com>
Subject Re: sessions and JSP Tag Handlers
Date Mon, 10 Jul 2000 23:44:57 GMT
"Craig R. McClanahan" wrote:

> Joel Regen wrote:
>
> > "Craig R. McClanahan" wrote:
> >
> > > Joel Regen wrote:
> > >
> > > >
> > > > 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.
> > >
> >
> > this is not working between pages. any ideas on why?
>
> It has worked for me in the past.

without using beans?

> Are you sure you are really in the same session in both pages
> (and the same web application)?

I am definitely NOT in the same session.  There is a problem with that.  But how do you ensure
that?

I've spent three days on this and another body has looked at it but we cannot determine why
a new
session is created for the 2nd page.
Also, the application context loses a reference (it goes null)...
Basically, the code goes something like this:

1st jsp page:
<pcs:init_payment_session/>
.....
<form ...action="uri to 2nd page">
<pcs:accepted_instruments/>
...</form>....

2nd jsp page:
....
<pcs:select_brand/>
....
handlers of interest are (respectively):
class InitPaymentSession extends TagSupport{... doStartTag( ){....
   pageContext.setAttribute( "MerchantID", (String)request.getParameter( "Globeset.PCS.MerchantID"
) , PageContext.SESSION_SCOPE );}
   pageContext.setAttribute( "foo",  foo,  PageContext.APPLICATION_SCOPE );
....}
class BrandSelector extends TagSupport{... doStartTag( ){....
    int ascope=PageContext.APPLICATION_SCOPE ;
    int sscope=PageContext.SESSION_SCOPE ;
    id          = (String)(pageContext.getAttribute( "MerchantID", sscope  ));
    foo       = (Foo)(pageContext.getAttribute("foo", ascope ));
    sc.log("got here 2: id is "+id);
    profile     = foo.getProfile(id);
....}

output:
got here 2: id is null
null pointer exception (foo is null).

No beans are involved.

> One thing to note is that Tomcat 3.1 has a bug if you are using sendRedirect() -- it
loses cookies
>
> and headers (including the session ID header).  Be sure you are using a recent build
of Tomcat 3.2
>
> beta if you want this to work across sendRedirect() calls.

not using it.



Mime
View raw message