Rob Schoening wrote:

> Is there a standard way to access the bean namespace from HttpSession?  If
> there was, you could write a servlet that instantiated and connected the
> beans to their respective back ends (RMI, CORBA, EJB, etc).
>
> Perhaps the Infobus could be rolled into the JSP runtime engines to allow
> these beans to discover each other...
>
> Any thoughts...
>
> Rob
>

Are you asking "can a servlet and a JSP access the same beans"?  If so, the
answer is yes, and it is the key to the "Model 2" approach described in the
0.92 spec.  No InfoBus or other magic is required.

In your JSP page, you declare a "lifespan" for the bean you are declaring in
the USEBEAN tag.  If you use a lifespan of "session", then any bean you store
(in a servlet) with HttpSession.putValue() is available to the JSP page as a
bean under the same name you stored it with!  The only thing you have to watch
out for is to use storage key names that are legal Java variable names,
because (at least in the reference implementation) the generated Java code
uses that name as the local variable that refers to the bean object.

Thus, you can do things like this:

* In a servlet, store a CustomerBean in the session like this:

    CustomerBean myCustomerBean = ....
    session.putValue("customer", myCustomerBean);

* Use ResourceDispatcher.forward() to internally redirect to
  a JSP page

* Access that bean like this:

    <USEBEAN name="customer" TYPE="CustomerBean" LIFESPAN="session">
    </USEBEAN>

Similarly, if you use LIFESPAN="page", you are requesting values that the
servlet has stored with HttpServletRequest.setAttribute().

The namespaces for servlets and JSP pages are identical, so sharing
information back and forth is really easy.

Craig McClanahan

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to