正 文

EJB的核心技术应用总结


www.7dspace.com  更新日期:2005-10-20 2:47:21  七度空间


  将Hello.jar加入到Apusic Application Server配置文件中。在/usr/apusic/config/server.xml 加入以下几行:

<module>
<EJB>
<EJB-uri>classes/Hello.jar
</EJB-uri>
<bean>
<EJB-name>Hello</EJB-name>
<jndi-name>HelloHome
</jndi-name>
</bean>
</EJB>
</module>

  启动服务器

  java -Xms64m com.apusic.server.Main -root /usr/apusic

  7、写客户端调用程序

  您可以从Java Client,JSP,Servlet或别的EJB调用HelloBean。

  调用EJB有以下几个步骤:

  通过JNDI(Java Naming Directory Interface)得到EJB Home Interface

  通过EJB Home Interface 创建EJB对象,并得到其Remote Interface

  通过Remote Interface调用EJB方法

  以下是一个从Java Client中调用HelloBean的例子:

  package EJB.hello;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import java.util.Hashtable;
  import javax.EJB.*;
  import java.rmi.RemoteException;
  /**
  * @author Copyright (c) 2000 by Apusic,
  Inc. All Rights Reserved.
  */
  public class HelloClient{
  public static void main(String args[])
  {
  String url = "rmi://localhost:6888";
  Context initCtx = null;
  HelloHome hellohome = null;  try{
  Hashtable env = new Hashtable();
  env.put(Context.INITIAL_CONTEXT_FACTORY,
  "com.apusic.jndi.InitialContextFactory");
  env.put(Context.PROVIDER_URL, url);
  initCtx = new InitialContext(env);
  }catch(Exception e){
  System.out.println("Cannot get initial
  context: " + e.getMessage());
  System.exit(1);
  }
  try{
  hellohome =
  (HelloHome)initCtx.lookup("HelloHome");
  Hello hello = hellohome.create();
  String s = hello.getHello();
  System.out.println(s);
  }catch(Exception e){
  System.out.println(e.getMessage());
  System.exit(1);
  }
  }
  }

  运行HelloClient,可得到以下输出:

  Hello World

10页,页码:[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 

上一篇:flash 8 swf metadate应用
下一篇:Java类加载内幕
作者:  来源:赛迪网 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐