Thursday, July 1, 2010

How to call EJB's in JSP's

@ 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...


Post a Comment

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Macys Printable Coupons