O'Reilly logo

MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL by James Turner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required