在servlet中调用和其他地方没有什么不同

解决方案 »

  1.   

    那个小程序是这样的:
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.util.Properties;
    import com.javapro.ejb.StringProcessor;
    import com.javapro.ejb.StringProcessorHome;public class Client {  public static void main(String[] args) {    // first argument must be the input
        if (args.length==0) {
          System.out.println("Please specify the input to convert to upper case.");
          return;
        }
        String input = args[0];    // preparing properties for constructing an InitialContext object
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        properties.put(Context.PROVIDER_URL, "192.168.0.8:1099");    try {
          // Get an initial context
          InitialContext jndiContext = new InitialContext(properties);
          System.out.println("Got context");      // Get a reference to the Bean
          Object ref  = jndiContext.lookup("StringProcessor");
          System.out.println("Got reference");      // Get a reference from this to the Bean's Home interface
          StringProcessorHome home = (StringProcessorHome)
            PortableRemoteObject.narrow (ref, StringProcessorHome.class);      // Create an Adder object from the Home interface
          StringProcessor sp = home.create();
          System.out.println ("Uppercase of '" + input + "' is " +
            sp.toUpperCase(input));
        }
        catch(Exception e) {
          System.out.println(e.toString());
        }
      }
    }嵌入servlet中后在InitialContext jndiContext = new InitialContext(properties);这捕捉到了错误,错误提示说:
    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
    不知为何,请大家指教
      

  2.   

    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        properties.put(Context.PROVIDER_URL, "192.168.0.8:1099");这两句注释掉吧
      

  3.   

    你的servlet和ejb是在同一个jvm里面吗?
    以前的java程序呢?
      

  4.   

    都不是,ejb在另一台服务器上,servlet和java程序都是本地的。是不是要实现RMI?但为什么那个java程序可以直接调用。
      

  5.   

    我也被这个问题疑惑很久了,主要是不太熟悉分布式系统。不明白如何把ejb部署到另外一台服务器上,也不知道如何在本地调用,有谁知道吗?并帮助解释一下,up