2 Replies Latest reply on Jul 26, 2002 5:58 AM by joelvogt

    How to call an EJB from a JSP!!!

    reckless

      I ahve successfully deployed an ejb( a simple statless ejb In JBOSS3.0.0.Now i want to call it from a jsp file how ???
      when i call the jsp file it asks for the java files present in the package...
      thnx..
      my code is

      <%
      try
      {
      Properties props = new Properties();
      props.put(Context.PROVIDER_URL,"http://localhost:8080");
      InitialContext ctx = new InitialContext(props);
      ejbjar.HelloHome home = (ejbjar.HelloHome) ctx.lookup("ejb/ejbjar.HelloHome");
      ejbjar.Hello hel=home.create();
      String retval=hel.sayHello("Pratap calling EJB via JSP");
      out.println("returned: "+ retval);
      hel.remove();
      }
      catch(java.rmi.RemoteException e)
      {
      out.println("remote Exception occured: "+e);
      }
      catch(javax.naming.NamingException e)
      {
      out.println("naming Exception occured: "+e);
      }
      %>

      so plz help...
      error is..........
      An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:69: Class ejbjar.HelloHome not found. ejbjar.HelloHome home = (ejbjar.HelloHome) ctx.lookup("ejb/ejbjar.HelloHome"); ^ An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:69: Class ejbjar.HelloHome not found. ejbjar.HelloHome home = (ejbjar.HelloHome) ctx.lookup("ejb/ejbjar.HelloHome"); ^ An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:70: Class ejbjar.Hello not found. ejbjar.Hello hel=home.create(); ^ 3 errors Date: Thu, 25 Jul 2002 11:47:53 GMT Server: Jetty/4.0.1 (Windows NT 4.0 x86) Servlet-Engine: Jetty/1.1 (Servlet 2.3; JSP 1.2; java 1.3.1_01) Content-Type: text/html Content-Length: 2895
      HTTP ERROR: 500 Unable to compile class for JSP An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:69: Class ejbjar.HelloHome not found. ejbjar.HelloHome home = (ejbjar.HelloHome) ctx.lookup("ejb/ejbjar.HelloHome"); ^ An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:69: Class ejbjar.HelloHome not found. ejbjar.HelloHome home = (ejbjar.HelloHome) ctx.lookup("ejb/ejbjar.HelloHome"); ^ An error occurred between lines: 5 and 25 in the jsp file: /clienthello.jsp Generated servlet error: C:\TEMP\Jetty__8080___hello\clienthello$jsp.java:70: Class ejbjar.Hello not found. ejbjar.Hello hel=home.create(); ^ 3 errors
      RequestURI=/hello/clienthello.jsp
      thnx in advnc
      pratap

        • 1. Re: How to call an EJB from a JSP!!!
          sharkman

          If you have an jar file with the required classes (local/remote and home interface of your beans), you can put it in the WEB-INF/lib/ directory of your .war file.
          Otherwise you can put the classes in the WEB-INF/lib/classes directory.

          Hope this helps.

          • 2. Re: How to call an EJB from a JSP!!!
            joelvogt

            you will need to make your ejb class files visible to your web side.
            To do this you should have a MANIFEST.MF in your war file with something like

            Manifest-Version: 1.0
            Class-Path: ./lib/my-ejb-client.jar


            (Make sure to put a few blank enter lines after the class path line too)