You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by May <ma...@hotmail.com> on 2001/08/23 04:15:16 UTC

call EJB from struts

Hello all !
Is there a recommended way to call EJB from the struts framework?

What I am doing now is...
I have StatefulSessionBean "EJB" and "EJB" has a
method getHello() which simply returns "Hello".

(1)ActionForm class
    (a) create setEJB(EJB ejb) and getEJB() methods.

(2)Action class
    (a) in the perform() method, first call the actionForm.getEJB() method.
    (b) if the result of (a) is null, create javax.ejb.Context context and
lookup EJB,
        create EJB instance.
    (c) call actionForm.setEJB(EJB ejb) method and save the EJB instance you
have
        created in (b).
    (d) call ejb.getHello() method and set the result to
        request.getSession().setAttribute("output from ejb",ejb.getHello).

(3)JSP
    (a) from JSP, call session.getAttribute("output from ejb").

Is there better way rather than setting output from EJB in Attribute?

Your experiences and suggstions will certainly be a great help !!

Thank you.
May