Properties props =new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL,"127.0.0.1:1099");
System.out.println("start to create context!");
Context ctx = new InitialContext(props);
System.out.println("start ejb client test");
Object obj=ctx.lookup("Example");
ExampleHome home = (ExampleHome)PortableRemoteObject.narrow(obj,ExampleHome.class);
Example example = home.create();

解决方案 »

  1.   

    在 weblogic中 : 
       Context ctx=null;
          Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY,
               "weblogic.jndi.WLInitialContextFactory");
            p.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
            ctx = new InitialContext(p);
           Object obj=ctx.lookup("ejb的绑定名");
           ExampleHome home=(ExampleHome) PortableRemoteObject.narrow             (obj,ExampleHome.class);
           Example    ejb=home.create();
      

  2.   

    最简单的办法Import你的ExampleEjbClient如 
    public class ExampleEjbClient
    {
       public static Example getEjb() throws 异常
       {
         try{
              Example home=(Example)HomeInterfaceFactory.create(Example.class,"XJTLMS/Example");
              Exam Exam =home.create();
               return Exam;
            }
          catch(CreateException e){
                  }
          return null;
       }
    }在Jsp就可以直接引用ExampleEjbClient.getEjb().(你自己的方法)我的服务器用的是WebLogic,希望对你有帮助!
      

  3.   

    在 weblogic中 : 
       Context ctx=null;
          Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY,
               "weblogic.jndi.WLInitialContextFactory");
            p.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
            ctx = new InitialContext(p);
           Object obj=ctx.lookup("ejb的绑定名");
           ExampleHome home=(ExampleHome) PortableRemoteObject.narrow             (obj,ExampleHome.class);
           Example    ejb=home.create();
      

  4.   

    public class ExampleEjbClient
    {
       public static Example getEjb() throws 异常
       {
         try{
              Example home=(Example)HomeInterfaceFactory.create(Example.class,"XJTLMS/Example");
              Exam Exam =home.create();
               return Exam;
            }
          catch(CreateException e){
                  }
          return null;
       }