Being Stateful

Suppose that you'd like a bean that is a little less flighty than a stateless session bean. You can create a stateful bean instead. For example, extend your cart bean to carry a total of items that you've added to your cart and then compute the tax and the total.

To begin, create a new set of classes based on the name StatefulCart (shown in Listings 17.9, 17.10 and 17.11).

Listing 17.9. StatefulCart.java
 package com.bfg.ejb.cart; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface StatefulCart extends EJBObject { public void clearTotal() throws RemoteException; public void addItem(double price, int quantity) throws RemoteException; public double getTotal() throws RemoteException; public double computeTax(String ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.