Accessing an EJB from JSP

Yet another way of accessing an EJB is from a JavaServer Pages (JSP) page. While JSP has largely been supplemented by newer technologies such as JavaServer Faces (JSF), it is still useful to understand how to incorporate an EJB into a JSP page since you may find yourself maintaining JSP code.

Getting ready

To use an EJB from a JSP client:

  1. Create the supporting EJB
  2. Use JNDI in the JSP client

    JNDI is required because JSP does not support DI.

How to do it...

Create a Java EE application called JSPExample. It should contain both a JSPExample-ejb and a JSPExample-war module. In the JSPExample-ejb module, we will create a remote session bean called ConstantsBean with methods returning common math constants. We will place it in the ...

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.