Writing the Client

Listing 6.7 demonstrates how a client accesses a stateful bean.

Listing 6.7. The Full Text of day06/Client.java
 package day06; import java.util.*; import javax.naming.*; import javax.ejb.*; public class Client { public static void main(String[] args) { print("Starting Client . . .\n"); Context initialContext = null; EnrollmentCartHome enrollmentCartHome = null; EnrollmentCart enrollmentCart = null; print("Demonstration of a simple client . . . \n"); try { // Looking up the enrollment cart home via JNDI initialContext = new InitialContext(); Object object = initialContext.lookup("day06/EnrollmentCartHome"); enrollmentCartHome = (EnrollmentCartHome) javax.rmi.PortableRemoteObject.narrow(object, EnrollmentCartHome.class); print("Creating ...

Get Sams Teach Yourself EJB in 21 Days 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.