Passing reference for Stateless Session Bean from JSP to JSP

I am trying to build a simple bookstore website as part of a school assignment. I am using EJB's, J2EE1.2.1 and JSP. I am not using any servlets at this point because I had trouble getting the deploy tool to work with them, but that is another story.

Essentially, here is what I am doing (Perhaps my design is what it flawed):

Using a jsp page to create an instance of a stateful session bean to serve as a shopping cart. I then want to pass the reference to this object to another jsp page where items can be added to the cart.From there I want to be able to pass the reference to this bean to another jsp page that would handle checkout and order processing. My problem is that I cannot seem to pass the reference to the bean. I am using session.setAttribute in the first page once the bean is created, and then I am using session.getAttribute in the next page to get this object's reference but it keeps coming up null. All of the examples I have seen on the web say to use this method for passing OBJECT references but none of them say whether or not you should be able to pass references to EJB Session objects this way from JSP to JSP. At any rate, that is exactly what I am trying to do. Below is some code that I use to create my Session bean. I have confirmed that the bean is being created, it just is not being transferred via the set/get/Attribute calls for some reason. Any advice you have would be appreciated!

The first jsp page has the following code:

<%

Cart shoppingCart;

try

{

InitialContext ic = new InitialContext();

Object objref = ic.lookup("MyCart");

System.out.println("lookup ok");

CartHome carthome = (CartHome)PortableRemoteObject.narrow(objref,CartHome.class) ;

System.out.println("narrow ok");

shoppingCart = carthome.create("Guest","999");

System.out.println("create ok");

session = request.getSession(true);

session.setAttribute("shoppingCart", shoppingCart);

}

catch(Exception e)

{

e.printStackTrace();

}

%>

The second page, that gets called from this one has the following code:

try

{

session = request.getSession(true);

Cart shoppingCart = (Cart)session.getAttribute("shoppingCart");

// If the user has no cart, create a new one

if (shoppingCart == null)

{

System.out.println("shoppingCart was null!");

InitialContext ic = new InitialContext();

Object objref = ic.lookup("MyCart");

System.out.println("lookup ok");

CartHome carthome = (CartHome)PortableRemoteObject.narrow(objref, CartHome.class);

System.out.println("narrow ok");

shoppingCart = carthome.create("Guest","999");

System.out.println("create ok");

session.setAttribute("shoppingCart", shoppingCart);

}

notice the line: if (shoppingCart == null), I have a system.out.println after it that prints out to the system.out file if the shoppingCart EJB is null, and it every time. So, for some reason, the reference is not being passed via the setAttribute, getAttribute calls. Please help! Thanks a bunch in advance!

Brad

PS: All includes are correct, as well as syntax, etc. Each page will display with no errors, it's just that the shopping cart is not coming along for the ride.

[3365 byte] By [honestcox] at [2007-9-26 2:25:45]
# 1
Ensure that the Cart object is serialized...Good LuckRaj K
karunar at 2007-6-29 9:37:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Use JSP actions.<jsp:useBean id="shoppingCart" class="com.package.Cart" scope="session"><jsp:setProperty name="shoppingCart" property="userName" value="Guest" /></jsp:useBean>
ybakos at 2007-6-29 9:37:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...