JSP Accessing EJB via Local Interface


EJB programming & troubleshooting: JSP Accessing EJB via Local Interface

  1. JSP Accessing EJB via Local Interface (6 messages)

    I am using WebLogic 6.1 and is trying to invoke a Session Bean from a JSP page via Local Interface. the JSP page and the EJB reside in the same domain. I am getting a ClassCastException .....

    java.lang.ClassCastException: cider.ejb.DBQueryBean_yu297a_LocalHomeImpl
            at jsp_servlet.__dbquerylocal._jspService(__dbquerylocal.java:107)
            at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:304)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:24
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2204)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

    Is there any configuration required from the web-app, ie web.xml (<local-ejb-ref>,....)?

    Thanks in advance!!!!

  2. I'm pretty sure that's because you can only use a local interface from another enterprise bean, not from a JSP page. You should try using a remote interface here.


  3. From EJB 2.0 specification:

    Session and entity beans may have local clients. A local client is a client that is collocated in the same
    JVM with the session or entity bean that provides the local client view and which may be tightly cou-pled
    to the bean. A local client of a session bean or an entity bean may be another enterprise bean (a ses-sion
    bean, entity bean, or message-driven bean).

    Unlike the remote client view, the local client view of a bean is not location independent. Access to an
    enterprise bean through the local client view requires the collocation in the same JVM of both the local
    client and the enterprise bean that provides the local client view. The local client view therefore does not
    provide the location transparency provided by the remote client view.
    A local client accesses a session or an entity bean through the bean&#8217;s local interface and local home
    interface. The container provides classes that implement the bean&#8217;s local and local home interfaces. The
    objects that implement the local home interface and local interface are local Java objects.
    The arguments and results of the methods of the local interface and local home interface are passed by
    reference. Enterprise beans that provide a local client view should therefore be coded to assume that the
    state of any Java object that is passed as an argument or result is potentially shared by caller and callee.
  4. Hi
    Even a servlet, JSP or any other java application can be a client for EJB. It is not necessary that client for a EJB must be a EJB.
    If u have j2sdkee1.3.1 server with u , u can see the samples application on how to call a EJB from JSP page.
    Here is the brief of source code.
     try {
            InitialContext ic = new InitialContext();
            Object o = ic.lookup("java:comp/env/CustomerBeanRef");
            LocalCustomerHome home = (LocalCustomerHome) o;

    Also u need to mention the local jndi name in weblogic-ejb-jar.xml


    Check out for any other possible errors.

  5. The plot grows thicker...

    From the spec (J2EE 1.3, page 100):
    The EJB container is required to support access to local enterprise beans. We recommend that the web container also support access to local enterprise beans. No support is provided for access to local enterprise beans from the application client container or the applet container.

    OK, so it looks like the web container MAY BE able to access the local interfaces, but it isn't required to. That would be the first thing to check, to see if your container supports it. If it can, I guess you would be able to access it via the local JNDI reference.

    Sorry for the misinformation...


  6. Check out this url for weblogic implementation of
    webcontainer access to local ejbs :

  7. Thanks a lot for all your feedbacks. Looks like it's possible for JSP/Servlet to access EJB via Local interface. The requirement is that the Web-App and EJB jar must be packaged in the same EAR file.