jsp的开头应将必要的包import
如:
<%@ page import="javax.ejb.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="你自己的包.类"%>
然后,程序中Properties props = System.getProperties();
Context ctx = new InitialContext(props);
HelloWorldHome lHome = (HelloWorldHome) lContext.lookup("jndi名");

解决方案 »

  1.   

    不好意思,最后一句打错了
    是:
    HelloWorldHome lHome = (HelloWorldHome)ctx.lookup("要调用的ejb的jndi名");
      

  2.   

    老大,j2ee最佳实践说:jsp千万别直接调用EJB,通过javabean或者servlet调用EJB
      

  3.   

    ice_dorothy(ice) :可是好象不对呀,还是找不,我把.class放到包test中,然后放到
    WEB-INF的classes里,可是出现这样的提示:test包找不到,怎么会事呢。
      

  4.   

    你的.class是在package test 里的吗 ???
      

  5.   

    ejb确认你发布成功了 ?
    然后把jsp贴出来看看 !
      

  6.   

    原来不在,我在jsp中引用javabean的时候一般要加包,所以就加了,但还是不可以。
    // ========= index.jsp ========<%@ page
       session="false"
       isThreadSafe="true"
       isErrorPage="false"
       import="javax.naming.*"
       import="javax.ejb.*"
       import="test.*"
    %><h4>Web Client</h4>
    <p><%
       try {
          Context lContext = new InitialContext();
          HelloWorldHome lHome = (HelloWorldHome) lContext.lookup(
             "java:comp/env/ejb/HelloWorld"
          );
          HelloWorld lSession = lHome.create();
          out.println( lSession.hello() );
       }
       catch( Exception e ) {
          out.println( "Caugth exception: " + e.getMessage() );
          e.printStackTrace();
       }
    %></p><br/><br/>
      

  7.   

    我在tmp里看了已经发布成功了,
      

  8.   

    你的ejb的home的jndi名字是什么?
    发布成功了吗?
    如果是HelloWorld.那下面改成
    HelloWorldHome lHome = (HelloWorldHome) lContext.lookup("HelloWorld");
    试试.另外,你的程序里哪里用到什么test.*** 了 ?
    哦,你的ejb用test包了...
    那就是:
    test.HelloWorldHome lHome = (test.HelloWorldHome) lContext.lookup("HelloWorld");
          
      

  9.   

    你的ejb的home的jndi名字是什么?什么意识,不明白,我才学,赐教,
      

  10.   

    我改成HelloWorldHome lHome = (HelloWorldHome) lContext.lookup("HelloWorld");也不可以,郁闷
     HelloWorldHome lHome = (HelloWorldHome) lContext.lookup(
             "java:comp/env/ejb/HelloWorld"
          );
    这一句做什么的
      

  11.   

    首先确认你的ejb部署是成功的,写个test看看。
    其次在
    HelloWorldHome lHome = (HelloWorldHome) lContext.lookup(
             "java:comp/env/ejb/HelloWorld"不使用java:comp/env/ejb/HelloWorld,而是直接使用HelloWorld中的jndi name试一试。或者在web.xml里加
    <ejb-ref>
        <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>test.HelloWorldHome</home>
        <remote>test.HelloWorld</remote>
     </ejb-ref>试一试吧,两种方法应该都可以。
      

  12.   

    HelloWorld中的jndi name试一试。
    什么是jndi name可以解释一下吗
      

  13.   

    <jndi-name>ejb/EJBTestRunner</jndi-name>
    就是jboss里的这一段内容。
      

  14.   

    <jboss>
       <enterprise-beans>
          <session>
             <ejb-name>HelloWorld</ejb-name>
             <jndi-name>ejb/HelloWorld</jndi-name>
          </session>
       </enterprise-beans>
    </jboss>
    你的jboss.xml里有这段内容吧?改成下面的试试
    HelloWorldHome lHome = (HelloWorldHome) lContext.lookup(
             "ejb/HelloWorld");
      

  15.   

    JNDI   -- java nameing and Directory interfaces  java 名字和目录接口是用来定位网络中java程序的.
      

  16.   

    还是不行
    -----------------我的web.xml------------------
    <web-app>
       
       <display-name>Web Client</display-name>
       <context-root>/web-test</context-root>
       
       <!-- The Welcome File List -->
       <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
          <welcome-file>index.html</welcome-file>
       </welcome-file-list>
       
       <ejb-ref>
          <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <home>HelloWorldHome</home>
          <remote>HelloWorld</remote>
       </ejb-ref>
       
    </web-app>--------------------------我的jboss-web.xml----------------------
    <jboss-web>
       <context-root>/web-test</context-root>
       <ejb-ref>
          <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
          <jndi-name>ejb/HelloWorld</jndi-name>
       </ejb-ref>
       
    </jboss-web>
    请指教。