This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Can someone please explain why <%= bean %> and <bean:write name="bean" /> give different results in the simplified code below. <jsp:useBean id="menuFactory" scope="application" class="menu.MenuFactory" /> <jsp:useBean id="menu" scope="session" class="menu.Menu" /> <% menu = menuFactory.getMenu("menu2"); %> <%= "1 " + menu %><br> 2 <bean:write name="menu" /><br> gives this output 1 Menu:menu2 2 Menu:null <-- why null and not menu2? I thought <bean:write> searched all scopes? Rich
Joined: May 30, 2002
I've got my answer! Turns out <jsp:useBean> as I used it, creates an instance of my bean (since none exists) and creates *2* references to it: one reference is stored in the session scope and is used for all the get/setProperty operations, the other reference is used as a scripting variable and has page scope. In my example code, when I assign a new value to the scripting variable the variable in session scope still has a reference to the bean created by <jsp:useBean>. Voila! now I understand my results. Rich