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.
To use an EJB from a JSP client:
- Create the supporting EJB
- 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 ...