James Morgenstein wrote:
> All-
>
> I am having some problems with retrieving my beans out of sessions on JSP
> pages.
>
> Some background, I'm using Tomcat 3.2b8 (also tried 3.1) with Apache 1.3.x
> on Linux with Sun's JDK1.3. Under Tomcat 3.2b8, I have disabled cookies and
> am using URL rewriting exclusively.
>
> My problem is this. I have declared the constructor on my Beans as private
> (contrary to the Bean pattern, but necessary for subclassing), because at
> the start of all operations within my system, I use a factory to construct
> the beans based on input parms. Once I construct the beans, I insert them
> into the session using:
> BeanClass instance = BeanClass.getInstance( subclass data );
> session.putValue( "beanName", instance );
> In my subsequent JSP pages I am using a useBean syntax with session scope to
> retrieve the beans for processing such as:
> <jsp:useBean id="beanName" scope="session"
> class="com.recommendit.beans.BeanSubClass" > </jsp:useBean>
>
> This is working properly for most of my pages and most of my users; however,
> I am occasionally getting errors on pages indicating that the bean cannot be
> created by the useBean syntax. This to me says that the bean is not in the
> session.
>
> Possible thoughts on the cause of this problem:
> 1) I am setting the bean in the session incorrectly (however, it works fine
> for the vast majority of my users)
> 2) Can the session be getting destroyed by some other outside influence?
> 3) ????
>
Sessions get destroyed only when they time out or when you invalidate them.
However, I'd bet the cause of your problem is a forgotten call to
response.encodeURL(). This will cause the next request in to start a new
session -- and if that request goes directly to a JSP page (so your bean
construction hasn't yet had a chance to execute) you will get the results you
see.
On the other hand, I don't see why you need a private constructor to allow
subclassing. I subclass things that have public constructors all over the place
(in both Tomcat and Struts) without problems, and I can't think of any benefits
to doing what you are doing.
>
> Thanks for the help.
>
> James
Craig