.

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

acct.doWhatever(...);
// etc etc...

0 comments:

Post a Comment

Facebook Twitter Delicious Digg More

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