5 Replies Latest reply on Dec 4, 2003 7:10 AM by dadaiut

    javax.servlet.ServletException: Lookup of java:/comp/env/ fa

    aschuettler

      Hi,

      I tried to install the Compute sample from JBoss IDE 1.2.0 Tutorial with configuration:
      Eclipse 2.1.0
      JBoss3.2.1/Tomcat4.1.24

      Tomcat is running on port 8085. After deploying I can call the compute form page at:

      http://localhost:8085/fibo/index.html

      After clicking the "Compute" Button of the form, the application can't find the InitialContext and throws the following exception:

      javax.servlet.ServletException: Lookup of java:/comp/env/ failed

      What did I do wrong? Any suggestions highly appreciated

      Andreas

        • 1. Re: javax.servlet.ServletException: Lookup of java:/comp/env
          jonlee

          You need to show the portion of code and probably the deployment descriptors so people understand what you are doing. Otherwise, only people who have played with the tutorial may be able to help.

          • 2. Re: javax.servlet.ServletException: Lookup of java:/comp/env
            aschuettler

            Hi,

            thanks for replying. Here comes the relevant code:

            1. Home Interface

            package tutorial.interfaces;

            public interface FiboHome
            extends javax.ejb.EJBHome
            {
            public static final String COMP_NAME="java:comp/env/ejb/Fibo";
            public static final String JNDI_NAME="Fibo";

            public tutorial.interfaces.Fibo create()
            throws javax.ejb.CreateException,java.rmi.RemoteException;

            }

            2. Relevant part of the servlet:

            public class ComputeServlet extends HttpServlet {

            private FiboHome home;
            private String value;

            [.....]

            public void init() throws ServletException {
            try {
            Context context = new InitialContext();
            value = (String) context.lookup
            ("java:/comp/env/Title");
            Object ref = context.lookup
            ("java:/comp/env/ejb/Fibo");
            home = (FiboHome)
            portableRemoteObject.narrow
            (ref, FiboHome.class);
            } catch (Exception e) {
            throw new ServletException("Lookup of
            java:/comp/env/ failed");
            }
            }
            }

            3. Form of the Client:





            Limit :
















            4. Servlet mapping in web.xml


            <servlet-name>ComputeServlet</servlet-name>
            <display-name>Computation Servlet</display-name>
            <![CDATA[Servlet that compute Fibonacci suite]]>
            <servlet-class>tutorial.web.ComputeServlet</servlet-class>


            <servlet-mapping>
            <servlet-name>ComputeServlet</servlet-name>
            <url-pattern>/Compute</url-pattern>
            </servlet-mapping>

            Thanks for your help

            Andreas

            • 3. Re: javax.servlet.ServletException: Lookup of java:/comp/env
              jonlee

              I think you have two problems. You haven't defined the local reference - java:comp/env/... is an internal reference for your web application. It doesn't link up with the global JNDI definition.

              Perhaps have a look at http://www.amitysolutions.com.au/documents/JBossJNDI-technote.pdf for some basic information on how the mappings are supposed to work. So you will need the definition in web.xml and a mapping in jboss-web.xml.

              Also note that you are using the remote interfaces whereas most of the technical note covers local interfaces. The final section touches on the remote interfaces. Essentially, you need ejb-ref definitions in web.xml. You'll also need to make sure that your ejb-ref.xml and jboss.xml in your EJB deployment is correct.

              Try and work through the theory anyway and post if you have any questions when creating your mapping.

              • 4. Re: javax.servlet.ServletException: Lookup of java:/comp/env
                mopromagik

                Hi, I to just finished the tutorial and got the same problem.

                The problem is caused by an error in the code of the tutorial. The line:

                * @jboss.ejb-ref-jndi ref-name = "ejb/Fibo"
                * jndi-name = "ejb/tutorial/Fibo"

                a the to of the ComputeServlet file should read:

                * @jboss.ejb-ref-jndi ref-name = "ejb/Fibo"
                * jndi-name = "tutorial/ejb/Fibo"

                to match the jndi-name we gave to the service.

                Hope that solves your problem.
                Mo

                • 5. Re: javax.servlet.ServletException: Lookup of java:/comp/env
                  dadaiut

                  Change to the following line in the file :

                  //value = (String) context.lookup"java:/comp/env/Title");
                  Object ref = context.lookup("/ejb/tutorial/Fibo");