程序中JNDI对吗?
有没有弄清EJB的各个接口
都是使用Weblogic做服务器吗?
上下文环境正确初始化了吗?

解决方案 »

  1.   

    回楼上的,已经初始化了,
     Properties props =new Properties(); 
     props.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory");
     props.setProperty("java.naming.provider.url","t3://192.168.2.163:7001");
     Context context = new InitialContext(props);
      

  2.   

    我写的一个简单的jsp调用ejb的。自己看看吧,希望对你有些帮助。
     <%@ page contentType="text/html; charset=GB2312" %>
    <%@ page import=" java.util.*;
         javax.ejb.*;
         javax.naming.*;
         javax.rmi.*;
         java.rmi.*;
         cmps.*;"
       %>
    <html>
    <head>
    <title>
    jsp1
    </title>
    </head>
    <body bgcolor="#00b46e">
    <center>
      <%
           out.println("jsp调用ejb显示<br>");
         try{
            Properties properties=new Properties();
            Context ctx;
            properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
            ctx=new InitialContext(properties);
            properties.put(Context.PROVIDER_URL,"t3://localhost:7001");
            Object hellojndi=ctx.lookup("UsertableRemote");
            UsertableRemoteHome home=(UsertableRemoteHome)PortableRemoteObject.narrow(hellojndi,UsertableRemoteHome.class);
           // UsertableRemote hello=(Hello)PortableRemoteObject.narrow(home.create(),UsertableRemote.class);
            Collection allusers=home.findAll();
            Iterator colIterator=allusers.iterator();
            UsertableRemote yuan;
            while(colIterator.hasNext()){
               yuan=(UsertableRemote)PortableRemoteObject.narrow(colIterator.next(),UsertableRemote.class);
               out.println("名字:"+yuan.getName()+" "+"密码:"+yuan.getPassword());
               out.print("<br>");
             }
           }
          catch(Exception ba){
             out.println(ba.getMessage());
            }
    %>
    </center>
    </body>
    </html>
      

  3.   

    那是不是要将EJB包含的类放在Weblogic的applications\DefaultWebApp\WEB-INF\classes下面,这样的话,JSP才可以找到相应的类,进面访问EJB呢?
      

  4.   

    我觉得可能是由于这样的原因:weblogic对不同的模块使用不同的类装载器,所以彼此之间看不到相互的类文件.要想解决此问题,有三种方法:1,把你的EJB类文件放在一个jar文件中,然后将其放在APP-INF/lib下.(你知道ear文件的结构吧!)2,把jar文件放在应用程序的根目录下,假设包含你编写的EJB class文件的jar文件叫EJB.jar,编写一个文本文件(假设为text),写如下内容:   
    Class-Path: EJB.jar    
    假设你的web应用程序的存档文件为:web.war,执行如下命令:  
    jar umf text web.war  
     应该就行了.3,在应用程序的weblogic-application.xml里定义一个classloader结构:
    <classloader-structure>
       <module-ref>
          <module-uri>EJB.jar</module-uri>
       </module-ref>
       <classloader-structure>     
          <module-ref>
             <module-uri>web.war</module-uri>
          </module-ref>
       </classloader-structure>
    </classloader-structure>
      

  5.   

    关于如何打包J2EE Web应用,继续学习ing...