1 Reply Latest reply on Feb 18, 2005 1:14 AM by kalyan120

    Servlet client unable to access SessionBean method

    bea

      Hello,
      I've deployed a simple SessionBean with jndi name="Libro"
      I've written a servlet, the client of the EJB, which tries to access to "saluda()", the method of the EJB. I get the following error when I compile the client:

      cannot find symbol
      symbol: variable sal
      location: myServlet
      sal.saluda();

      Here is the code for the servlet:

      res.setContentType("text/html");
      PrintWriter out = res.getWriter();

      out.println("");
      out.println(" Cliente EJB ");
      out.println("");

      try
      {
      Context contexto = new InitialContext();
      Object ref = contexto.lookup("Libro");
      LibroHome home =
      (LibroHome) PortableRemoteObject.narrow(ref,Beans.LibroHome.class);
      Libro sal = home.create();
      }

      catch (Exception e)
      {
      e.printStackTrace();
      }


      sal.saluda();//<---------HERE IS THE ERROR
      out.println("");
      out.close();


      The "saluda()" method only prints a greeting, it's quite simple.

      I don't know what is wrong? maybe the package?? I'm really confused :S

      Any help will be welcome

        • 1. Re: Servlet client unable to access SessionBean method

          You have to declare Libro sal, outside the try,catch block. Otherwise it's not visible to the statements outside the block.

          Libro sal = null;
          try
          {
          Context contexto = new InitialContext();
          Object ref = contexto.lookup("Libro");
          LibroHome home =
          (LibroHome) PortableRemoteObject.narrow(ref,Beans.LibroHome.class);
          sal = home.create();
          }

          catch (Exception e)
          {
          e.printStackTrace();
          }


          sal.saluda();
          out.println("");
          out.close();


          Thanks,
          Kalyan.