How to access Session Bean from JSP in GlassFish
First add a reference in deployment descriptor to the session bean.
<ejb-local-ref>
<ejb-ref-name>AccountTypeFacadeRef</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.my.ejb.AccountTypeFacade</local>
<ejb-link>BankApp-ejb.jar#AccountTypeFacade</ejb-link>
</ejb-local-ref>
is optional.
In JSP use JNDI lookup to find the resource.
<%
String prefix = "java:comp/env/";
String ejbRefName = "AccountTypeFacadeRef";
String jndiUrl = prefix + ejbRefName;
javax.naming.Context ctx = new javax.naming.InitialContext();
AccountTypeFacade atf = ( AccountTypeFacade ) ctx.lookup( jndiUrl );
List<AccountType> accountTypeList = atf.findAll();
%>
0 comments: