useBean functionality

i have a servlet centric architecture where i am creating a bean in the servlet and passing it to a jsp using the setAttribute() method.

MyBean myObject = new MyBean();

myObject.setProperty1(value);

myObject.setProperty2(value);

request.setAttribute( "obj", myObject );

once it gets to my jsp, i want to get the object and maintain its persistance throughout the scope of the session. to do this, i am TRYING to use the <jsp:useBean/> tag, but it is creating a NEW object and not retrieving the one passed by the servlet.

<%@ page import="myPackage.MyBean" session="true" %>

<jsp:useBean id="obj" class="MyBean" scope="session"/>

<%

if (null != obj)

System.out.println("bean is NOT null");

else

System.out.println("bean is null");

%>

according to "Web Development with JavaServer Pages" by Fields & Kolb, pg 226 - this should be possible. if it is NOT, can someone instruct me on how to maintain the objects persistance using getAttribute()? i would prefer to use the <jsp:useBean/> tag if possible, though.

[1139 byte] By [mkowales] at [2007-9-26 1:52:02]
# 1
From the servlet code, why don't you set it into the HTTP session itself using HttpSession.setAttribute() instead of HttpRequest.setAttibute()You can get it from JSP code using session.getAttribute()
neville_sequeira at 2007-6-29 3:01:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

try this :

HttpSession session = request.getSession();

MyBean myObject = new MyBean();

myObject.setProperty1(value);

myObject.setProperty2(value);

//request.setAttribute( "obj", myObject );

session.setAttribute( "obj", myObject );

Retrieve using the getAttribute method of the session object

vdsharma at 2007-6-29 3:01:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...