文档介绍:作者:jeru
日期:2001-3-6 11:23:09
jsp与ejb通信
Blueski编译
以下是一个snippet代码,演示了JSP页面如何与 EJB session bean进行相互作用。
<%@ page import=".*, ,
, " %>
<%!
//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
txt = new InitialContext( );
Object ref= ("p/env/ejb/AccountEJB");
accHome = (AccountHome)(ref,);
}
%>
<%
//instantiate the session bean
Account acct = ();
//invoke the remote methods
(...);
// etc etc...
%>
在JSP中java代码应该越少越好。
在以上例子中,JSP设计者不得不处理和理解存取EJB的机理。代替在一个Mediator中对EJB机制的压缩以及将EJB方法作为Mediator的方法,
可以在jsp中使用 Mediator。Mediator通常由EJB设计者编写。Mediator可以提