Cory L Hubert wrote:
> Right now I am using Model 2 which uses Servlets to call all the set
> methods on the beans and JSP just calls get methods. I need to make sure
> that JSP & Servlets manipulate the right Bean instance. Any Idea on how I
> can do this?
>
That is actually pretty simple ... just use the same bean names.
Using a session bean as an example, let's say you did the following in your
servlet:
HttpSession session = request.getSession(true);
MyObject myObject = new MyObject(....);
myObject.setName("My Name");
session.putValue("thisOne", myObject);
Now, the session bean is stored in the session under the key "thisOne". To
reference it in a JSP page that you forward to:
<jsp:useBean id="thisOne" scope="session" class="..."/>
The name is <%= thisOne.getName() %>.
The fact that you used "thisOne" as both the storage key and the bean id is what
ensures they refer to the same object. Keys need to be unique within a particular
scope (for example, all session beans have to have a unique name), but the names
themselves need have no relationship with the class name or anything else. I try
to use mnemonic names because the name becomes a variable name in the JSP page.
Craig McClanahan
===========================================================================
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