关键是为每个bean建一个句柄,以后就可以引用,做购物车的时候可以用这个方法,也可以用到动态代理。
if (cartHandle == null)
{
System.out.println("3");
Context ctx = getInitialContext();
Object obj = ctx.lookup("Cart");
CartHome cartHome = (CartHome) javax.rmi.PortableRemoteObject.
narrow(obj, CartHome.class);
CustomerDto cusDto=null;
cusDto=(CustomerDto)mysession.getAttribute("userDto");
Cart cart = cartHome.create(cusDto);
cartHandle = cart.getHandle();//得到有状态会话bean的HANDLE通过HANDLE来调用这个会话bean。
cart.addItem(item);
HttpSession session = servletRequest.getSession(true);
session.setAttribute("cartHandle", cartHandle);
//只创建一次,因为上面的HANDLE
// saveToken(servletRequest);//利用同步令牌解决同步提交问题
Map map = cart.getDetail();
Collection collection = map.values();
iterator = collection.iterator();
list.clear();
while (iterator.hasNext())
{
ItemValue _item = (ItemValue) iterator.next();
list.add(_item);
}
double ret=cart.getTotal();
mysession.setAttribute("totalPrice",new Double(ret));//在客户端调用
mysession.setAttribute("shoppinglist", list);
}