3 Replies Latest reply on Mar 10, 2011 9:53 AM by couse1

    EJB and JSP

    couse1

      Hi,

       

      I'm trying to call EJB from JSP.

       

      My EJB :

       

      package ejb;

      import javax.ejb.Stateless;

      import org.jboss.ejb3.annotation.Clustered;

      @Stateless

      @Clustered

      public class CompteurEJB implements CompteurEJBRemote {

       

          @Override

          public void affiche(int msg) {

              System.out.println(msg);

       

          }

       

      }

       


      My remote EJB :

      package ejb;

      import javax.ejb.Remote;

       

      @Remote

      public interface CompteurEJBRemote {

          public void affiche(int msg);

      }

       

      And this package ejb is in ejbSLSBCluster.jar.

       

      My client (JSP) :

       

      <?xml version="1.0" encoding="UTF-8" ?>

      <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

      <%@ page import= "ejb.CompteurEJBRemote"%>

      <%@ page import= "javax.naming.*"%>

      <%@ page import= "java.text.*"%>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

      <title>JSP de stress</title>

      </head>

      <body>

          <table>

              <%!

                  public void jspInit () {

                      try {

                          InitialContext ctx = new InitialContext();

                          CompteurEJBRemote s = (CompteurEJBRemote) ctx.lookup("CompteurEJB/remote");

                          for (int i = 0; i < 300; i++) {

                              %><tr><td>test<%!

                              s.affiche(i);

                              %></td></tr><%!

                           }

                      }

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

                  }

              %>

          </table>

      </body>

      </html>

       

      My JSP is in .war where i have :

       

      ejbSLSBCluster.jar in WEB-INF/lib

       

      jndi.properties in WEB-INF :

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

      java.naming.provider.url=jnp://127.0.0.1:1099

      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

       

      My web.xml :

       

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

          id="WebApp_ID" version="2.5">

          <display-name>clientcompteurweb</display-name>

       

          <servlet>

              <description>Point d'entree de l'application</description>

              <display-name>Controlpea</display-name>

              <servlet-name>Controlpea</servlet-name>

              <servlet-class>com.saintquentin.pea.Controlpea</servlet-class>

          </servlet>

          <servlet-mapping>

              <servlet-name>Controlpea</servlet-name>

              <url-pattern>/Controlpea</url-pattern>

          </servlet-mapping>

       

          <resource-env-ref>

              <description>Bind de mon bean</description>

              <resource-env-ref-name>CompteurEJB/remote</resource-env-ref-name>

              <resource-env-ref-type>ejb.CompteurEJB</resource-env-ref-type>

              <mapped-name>java:CompteurEJB/remote</mapped-name>

          </resource-env-ref>

       

      </web-app>

       

      But when i execute my jsp i have this error :

      17:06:27,649 ERROR [STDERR] javax.naming.NameNotFoundException: CompteurEJB not bound

       

      I think that i forgot something but what??

       

      I use JBOSS 5.1 and Eclipse 3.4

       

      Thanks for your help