我已经知道了。假如你的EJB为A,你将A.class,AHome.class放到你的webApplication的WEB-INF/classes下面就行了。注意包名的问题。要不然就会出现转型错误。你小心我告你盗版啊。
哈哈……

解决方案 »

  1.   

    我的WEB-INF/classes/hh/ 下有那两个文件,不是直接在class下,
    可错误依然,
    我盗版你,却盗版不了你的成功!
    唉~~~~~~~~
      

  2.   

    你不要新建那两个接口类,直接从JB的发布目录(classes)复制这两个接口类到Web服务器的classes相应目录下试试
      

  3.   

    我是把这两个接口类复制过去的,ejb项目是aa, 我新建的测试的项目是bb,
    我在测试项目上新建web和servlet,复制了aa的src下的remote.java和home.java,
    到bb的src下,并把remote.java的package aa改做package bb,然后编绎成.war,并布暑成功!
    然后运行servlet就出现了上面的问题!
    后来我又把aa下的remote.class和home.class拷到bb下的class,还是不行!
    还是有上面问题!
      

  4.   

    错误信息:
    start...lookup OKError narrow:Cannot narrow remote object to qq.bean1Homecreate:null Error in HelloWorld(): Remote interface reference is null. It must be created by calling one of the Home interface methods first. Calling HelloWorld() null  ambest(许愿) :我servlet程序和你一样的!(在上面)
      

  5.   

    servlet程序:package qq;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import javax.naming.*;
    import java.util.Properties;
    import javax.rmi.PortableRemoteObject;
    /**
     * <p>Title: ambest</p>
     * <p>Description: EJBtest</p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: AMB</p>
     * @author ambest
     * @version 1.0
     */public class Servlet extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      private static final String ERROR_NULL_REMOTE = "Remote interface reference is null.  It must be created by calling one of the Home interface methods first.";
      private static final int MAX_OUTPUT_LINE_LENGTH = 100;
      private boolean logging = true;
      private bean1Home h= null;
      private  bean1 b= null;
      PrintWriter out;  private Context getInitialContext() throws Exception {
        String url = "t3://hzh:7003";
        String user = null;
        String password = null;
        Properties properties = null;
        try {
          properties = new Properties();
          properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          properties.put(Context.PROVIDER_URL, url);
          if (user != null) {
            properties.put(Context.SECURITY_PRINCIPAL, user);
            properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
          }      return new InitialContext(properties);
        }
        catch(Exception e) {
          out.println("Unable to connect to WebLogic server at " + url);
          out.println("Please make sure that the server is running.");
          throw e;
        }
      }  //Initialize global variables
      public void init() throws ServletException {
      }
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>ServletEJBTest</title></head>");
        out.println("<body>");    long startTime = 0;
        try {
          //get naming context
          Context context = getInitialContext();
          out.println("<br/>start...<br/>");//调试时的输出信息。
          //look up jndi name
          Object ref = context.lookup("bean1");
          out.println("lookup OK<br/>");
          //look up jndi name and cast to Home interface
          //sessionBean1Home = (SessionBean1Home)ref;
        h=(bean1Home)PortableRemoteObject.narrow(ref,bean1Home.class);
          //这两种方法是同样的问题。
          //错误码应该是在这一行出的问题吧。
          if (logging) {
            long endTime = System.currentTimeMillis();
            out.println("Succeeded initializing bean access through Home interface.");
            out.println("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          out.println("<font color=red>Error narrow:"+e.getMessage()+"</font><br/>");
        }
        //create();
        try {
          b =h.create();
          out.println("create ok");
          if (logging) {
            long endTime = System.currentTimeMillis();
            out.println("Succeeded: create()");
            out.println("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          out.println("create:"+e.getMessage());
        }    if (b== null) {
          out.println("Error in HelloWorld(): " + ERROR_NULL_REMOTE);
        }
          out.println("Calling HelloWorld()");
          startTime = System.currentTimeMillis();    try {
          out.println("Hello World:"+b.helloworld("ddd"));
          if (logging) {
            long endTime = System.currentTimeMillis();
            out.println("Succeeded: HelloWorld()");
            out.println("Execution time: " + (endTime - startTime) + " ms.");
          }
        }
        catch(Exception e) {
          out.println(e.getMessage());
        }    //out.println("<p>The servlet has received a " + request.getMethod() + ". This is the reply.</p>");
        out.println("</body></html>");
      }
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
      }
      //Clean up resources
      public void destroy() {
      }
    }