Creating a simple session EJB

In this recipe, we will create a simple session bean that returns either a formal or an informal salutation based on a string parameter. In the next recipe we will see how to invoke this EJB from a servlet.

Specifically we will create a stateless session bean. A stateless session bean does not remember its previous invocations. A user will call the bean and the bean will return a result. A stateless bean is not good for maintaining the state of an interactive session such as required to maintain a list of purchases. However, it is useful for one-time calculations. Our bean returns one of two simple greetings.

Getting ready

The creation of a session EJB consists of two steps:

  1. Create the EJB class annotated with a session ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

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