Call EJB from JSP page

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Call EJB from JSP page

The following is a code snippet that demonstrates how a JSP page can interact with an EJB session bean:

<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
//declare a "global" reference to an instance of the home interface of the session bean
AccountHome accHome=null;

public void jspInit()
//obtain an instance of the home interface

InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome = (AccountHome)PortableRemoteObject.narrow(ref,Accou ntHome.class);
//instantiate the session bean

Account acct = accHome.create();
//invoke the remote methods

// etc etc...