Creating a Stateless Session Bean

Now you can move on to actually creating your first EJB. To begin, create a new subdirectory called ejb in your com/bfg source hierarchy. You're going to move the logic that computes sales tax into a bean called Cart. Start by writing the remote interface (see Listing 17.1), which extends EJBObject. There's not much to it really—it just declares the calling parameters for the computeTax call and specifies that it throws RemoteException, as all EJB beans must.

By convention, if a bean implements a functionality called Foo, the remote interface is called Foo, the home interface is called FooHome, and the enterprise bean is called FooBean.

Listing 17.1. Cart.java
 package com.bfg.ejb.cart; import javax.ejb.EJBObject; ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.