O'Reilly logo

EJB 3.1 Cookbook by Richard M. Reese

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

Accessing the session bean using JNDI

JNDI can also be used to access an EJB but using this technique is not as easy as DI. The Salutation EJB from the first recipe and the servlet from the second recipe are used to illustrate this technique.

Getting ready

To use JNDI in a client:

  1. Obtain an InitialContext object
  2. Use the context to look up the EJB

    Familiarize yourself with the Salutation session bean and its two methods as developed in the Creating a Simple Session EJB recipe. We will also modify the SalutationServlet from the second recipe to use JNDI instead of DI.

How to do it...

A portable JNDI name syntax has been added to EJB 3.1. We will use this syntax as it makes the use of JNDI less dependent on the deployment server.

The modification of the ...

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