调用他可以写个servlet调。可以调jndi name

解决方案 »

  1.   

    我用的开发环境是sun的
    j2se + j2ee 比较轻量级的那种,我在客户机和服务器上都安装了同样的运行环境.
      

  2.   

    偶做的都是本机调用,远程也没成功过,好像先要配好JNDI服务。帮你UP
      

  3.   

    Hashtable ht = new Hashtable();
    ht.put(ctx.PROVIDER_URL, "t3://ip:port"); //不要问我ip:port是什么哦:)
    ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    initctx = new InitialContext(ht);不想抢分了,这个问题也回答了不知道多少遍了...怎么就没人保存一下在贴上 :)
      

  4.   

    以前的一个学习程序,改改吧 :)
    package com.learnweblogic.examples;import java.util.Properties;import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;public abstract class BaseClient {  private Context ctx;  private String url = "t3://localhost:7001";  protected Object narrow(Object o, Class c) {
        return PortableRemoteObject.narrow(o, c);
      }  protected Context getInitialContext()
        throws NamingException
      {
        if (ctx == null) {      try {        Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
            p.put(Context.PROVIDER_URL, url);
            ctx = new InitialContext(p);      } catch (NamingException ne) {
            System.err.println("** Unable to connect to the server at:"
              +url);
            ne.printStackTrace();
            throw ne;
          }    }    return ctx;
      }  public BaseClient(String [] argv) {    if (argv.length > 0) url = argv[0];
      }
        
    }
    package com.learnweblogic.examples;import com.learnweblogic.examples.BaseClient;import javax.naming.Context;
    import javax.naming.NamingException;
    import javax.rmi.PortableRemoteObject;public final class HelloWorldClient extends BaseClient {  private Context ctx;  HelloWorldClient(String [] argv) 
        throws NamingException
      {
        super(argv);    ctx = getInitialContext();  }  public void runClient() 
        throws Exception
      {
        
        HelloWorldHome home = null;    try {
          Object h = ctx.lookup("HelloWorldEJB");      home = (HelloWorldHome)
            PortableRemoteObject.narrow(h, HelloWorldHome.class);
        } catch (NamingException ne) {
          System.err.println("Unable to lookup the HelloWorld EJB.");
          System.err.println("Please make sure that the bean has been deployed"+
            ", and the client's classpath has been set correctly.");      throw ne;
        }    try {
          HelloWorld hw = home.create();      System.out.println("Say Hello to EJB.");      String ejbSays = hw.helloWorld();      System.out.println("The EJB said: "+ejbSays);
        } catch (Exception e) {
          System.err.println("Received an unexpected exception " + e
            + " while using the HelloWorldEJB.");      throw e;
        }
      }  public static void main(String[] argv) 
        throws Exception
      {
        HelloWorldClient hwc = new HelloWorldClient(argv);    hwc.runClient();  }
    }
      

  5.   

    俺说两句:
        1.保证服务器端的ejb成功的发布,需要注意的是准备调用的jndi的名要确认一下。
        2.客户端的程序,按照 模范老公说的初始化initctx,然后根据确认了的jndi名
          就可以调ejb了。
      

  6.   

    谢谢大家的回答,虽然想要得东西与我的需求不是完美一致,也知道如何做了.j2sdk1.4.1_02 + j2sdkee1.3.1 环境下的Hashtable ht = new Hashtable();
    ht.put(ctx.PROVIDER_URL, "t3://ip:port"); //不要问我ip:port是什么哦:)
    ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    initctx = new InitialContext(ht);................这个具体如何写就更好了..................(送100分)