你的InitialContext方法在TOmcat中调用的吧?你使用一个空的InitialContext试试
Context initctx=new InitialContext();

解决方案 »

  1.   

    运行在tomcat上的jsp代码如下:
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="java.util.*"%>
    <%@ page import="javax.naming.*"%>
    <%@ page import="javax.rmi.PortableRemoteObject"%>
    <%@ page import="testejb.*"%>
    <html>
    <head>
        <title>TestPage</title>
    </head>
    <%!
        private Context getInitialContext() throws Exception
        {
            String url = "t3://192.168.1.130:7001";
            String user = null;
            String password = null;
            Properties properties = null;        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);
        }
    %>
    <body bgcolor="#ffffff">
    <%
        SampleHome sampleHome = null;
        Sample sample = null;    //查找Home接口,创建对象引用
        try
        {
            //get naming context
            Context context = getInitialContext();        //look up jndi name
            Object ref = context.lookup("Sample");
            //look up jndi name and cast to Home interface
            sampleHome = (SampleHome) PortableRemoteObject.narrow(ref, SampleHome.class);        //
            sample = sampleHome.create();
        }
        catch (Exception ex)
        {
            out.println("查找Home接口出错:" + ex);
        }    //调用EJB对象
        try
        {
            if (sample == null)
                throw new Exception("EJBObject is null.");
            //
            Vector v_result = sample.getUserList();
            while(!v_result.isEmpty())
                out.println("<br/>\t" + v_result.remove(0));
        }
        catch (Exception ex)
        {
            out.println("调用EJB对象出错:" + ex);
        }
    %>
    </body>
    </html>
      

  2.   

    使用一个空的InitialContext,错误为:找不到jndiname我使用JBuilder9,代码放在javabean中,代码和楼上一样,
    运行错误:"Cannot instantiate class: weblogic.jndi.WLInitialContextFactory"
    将properties属性改为:
        Context.PROVIDER_URL="iiop://wsg-2:7001";
        Context.INITIAL_CONTEXT_FACTORY="com.sun.jndi.cosnaming.CNCtxFactory";
        Context.SECURITY_PRINCIPAL="username";
        Context.SECURITY_CREDENTIALS="password";    new InitialContext(properties);通过;无问题,但运行到:
        //look up jndi name
        Object ref = (com.wsg.ecom.data.DataHome) context.lookup("Data");
        dataHome = (DataHome)PortableRemoteObject.narrow(ref, DataHome.class);
      
      错误:java.lang.NoClassDefFoundError: javax/ejb/EJBHome
      是否要tomcat对配置?
      

  3.   

    http://expert.csdn.net/Expert/topic/2843/2843813.xml?temp=.9221155
      

  4.   

    JNDI这个的确很麻烦,我用Jbuilder和Weblogic也是报这种错误,但我在java.sun的j2ee里就可以正常运行。主要就是下面这两个,好像总是不对。
    Context.PROVIDER_URL="iiop://wsg-2:7001";
    Context.INITIAL_CONTEXT_FACTORY="com.sun.jndi.cosnaming.CNCtxFactory";我也是个J2EE新手UPUPUPUPUPU
      

  5.   

    看过:http://expert.csdn.net/Expert/topic/2843/2843813.xml?temp=.9221155
    把WEblgoic的jar放到tomcat\common\lib下,问题依旧我使用JBuilder9,代码放在javabean中,工程中将ejb设为weblogic,sevlet/jsp设为tomcat,
    naming设为tomcat。
    那位能详细解释Context.PROVIDER_URL,Context.INITIAL_CONTEXT_FACTORY 的确切含义
      

  6.   

    TomCat支持EJB吗?????!!!!
      

  7.   

    TomCat不支持EJB,但支持naming,所以支持访问EJB
      

  8.   

    把 j2ee.jar 拷贝到 tomcat\common\lib下
    然后把客户端类包(WAR文件)部署到 你的JSP发布目录,如果没有打包,至少在
    WEB发布目录\WEB-INF\class 下面应该有 DataHome.class(本地接口) 和 Data.class(我假设的你的远程接口)
    再试试看
      

  9.   

    tomcat 安装好之后,只需要把你的程序包放到$Tomcat_Home$/webapps下就可以直接使用了。
    这样会使webapps越来越大就需要设置虚拟目录:
    1.单个应用设置:
     在<Host>和</host>之间加上
     <Context path="/site" docBase="d:\site" reloadable="true" debug="0">
     </Context>
     参数:path 表示在浏览器中输入http://localhost:8080/site
         docBase表示你的程序包的物理绝对路径,默认的绝对路径是$Tomcat_Home$/webapps
     这样设定了之后会在$tomcat_home$/conf/catalina/localhost目录下生成一个site.xml文件,此文件的内容就是刚才设置的内容。
    2.通过前面我们知道了在$tomcat_home$/conf/catalina/localhost目录下会生成相应的配置文件,因此我们可以直接在$tomcat_home$/conf/catalina/localhost目录下写配置文件文件名任意取,最好是跟你的web应用相同便于管理,如site.xml内容同上
    <Context path="/site" docBase="d:\site" reloadable="true" debug="0">
     </Context>
    3.更改整个根目录:
      找到<Host name="localhost" debug="0" appBase="webapps" 
      unpackWARs="true" autoDeploy="true">
     将appBase的设置成期望的路径(绝对路径)
     出现的问题:输入:http://localhost:8080/没有出现默认的页面
     原因当然是更改了路径造成的。解决也很简单了,把文件拷过来,或者再把原来默认的设成虚拟路径。