在下面的代码中,Mediator中对EJB机制的压缩以及将EJB方法作为Mediator的方法,可以在jsp中使用  Mediator。Mediator通常由你自己根据个人需要编写。Mediator可以提供附加的值如attribute  caching等.    
 
 
<%@  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,AccountHome.class);    
 
}    
 
%>    
 
<%    
 
//instantiate  the  session  bean    
 
Account  acct  =  accHome.create();    
 
//invoke  the  remote  methods    
 
acct.doWhatever(...);    
 
//  etc  etc...    
 
%>