Hi Jeff,
Let me have a shot at this one. What you are describing below resolves to a
more general object referencing issue that still occasionally catches me
today, unless I start drawing pictures :-) The code you quoted, when turned
into a servlet, would end up looking something like:
// Very rough translation of the usebean tag, assuming the object
// already existed in the session for simplicity.
BeanClass beanId = BeanClass(sessionHashTable.get("beanId"));
BeanClass newBean = new BeanClass();
newBean.setName("New Name");
beanId = newBean;
So, at the end of this code, the *locally* declared reference "beanId" will
indeed now refer to the new BeanClass instance (called "New Name"). However
when the page completes, all these references will go out of scope and the
new BeanClass instance becomes eligable for garbage collection. The
original BeanClass is still safely tucked away in the session's Hashtable,
untouched, it was just pointed at by the beanId identifier for a little
while...
I think the only way to swap the object stored in the session would be to
"overwrite" it with the new object, stored under the same name? eg.
instead of beanId = newBean;
use
session.setAttribute("beanId", newBean);
in the JSP page.
Regards
Drew Cox
Barrack Consulting
> -----Original Message-----
> From: Bail . Jeff [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, January 14, 2000 5:56 AM
> To: [EMAIL PROTECTED]
> Subject: Basic Session Scope Question
>
> If I instantiate a bean:
>
> <jsp:useBean id="beanId" scope="session" class="BeanClass" />
>
>
> Shouldn't I be able to do something like:
>
> <%
> BeanClass newBean = new BeanClass();
> newBean.setName("New Name");
> beanId = newBean;
> %>
>
>
> At this point, on all subsequent pages I would expect that if I were to
> use
> the same jsp:useBean tag the object I would get back would be newBean. But
> this doesn't seem to be the case -- it always returns the original bean
> (which does not have the Name propery set). Are you actually allowed to
> change the object reference in this way?
>
>
>
> Jeff Bail...
>
> ==========================================================================
> =
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html