你的应用服务器是什么?jsp和servlet在什么server上?

解决方案 »

  1.   

    sorry 我忘了说,我的环境是jboss-3.0.6 + tomcat-4.1.18整合版,jsp和servlet都在\server\default\deploy\hello.war目录下,EJB在\server\default\deploy\hello.jar包中
      

  2.   

    JNDI名保证正确吗?试试:
    Object objRef = context.lookup("Hello");
    YourHome home = (YourHome)PortableRemoteObject.narrow(objRef, YourHome.class);
      

  3.   

    我是这样写的啊,可是没用。我想知道在什么情况下会“Connection refused”。为什么在jsp中能过,在servlet中不能过?jsp不也要翻译成servlet的吗。
      

  4.   

    可能是找不到你的应用服务器
    你在lookup的时候,写出你jboss的ip地址试试看
      

  5.   

    InitialContext ic = new InitialContext();初始化上下文的时候
      

  6.   

    不好意思,我还是不知道如何写出jboss的地址,javalovers(飞飞)兄, 可以给出具体代码吗?
      

  7.   

    例如:
    _____________________________________________________________________________
    package hello.ejb;import java.util.*;
    import java.io.*;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;public class HelloClient
    {   public static void main(String[] args)
       {     
          try
          {
            //jndi配置,硬编码到java中,应实现为外部属性文件
            Properties p=new Properties();
            p.setProperty("java.naming.factory.initial",
                "org.jnp.interfaces.NamingContextFactory");
            p.setProperty("java.naming.provider.url",
                "localhost:1099");        
             //out print jndi配置
            p.list(System.out);      
             // Get a naming context
             InitialContext jndiContext = new InitialContext(p);
             System.out.println("Got context");         
             // Get a reference to the Interest Bean
             //jboss默认jndi名为ejb-jar.xml中的:ejb-name
             Object ref  = jndiContext.lookup("Hello");
             System.out.println("Got reference");         
             // Get a reference from this to the Bean's Home interface
             HelloHome home = (HelloHome)
             PortableRemoteObject.narrow(ref, HelloHome.class);         
             // Create an Hello object from the Home interface
             Hello hello = home.create();        
             // call the hello() method 
             System.out.println(hello.hello());
          }
          catch(Exception e)
          {
             System.out.println(e.toString());
          }
       }
    }