What I do (and I'm getting a feel for J2EE myself) is to interpose a
JavaBean. I don't think that this is absolutely required (i.e. I think that
direct access of EJBs from JSP pages is permitted), but on the other hand I
don't want a chunk of pure presentation (the JSP) directly calling an entity
bean, either, so even if one could directly access I don't think I would.

The intermediate JavaBean is part of the Web component containing the JSP.
It uses the standard mantra for obtaining a reference to an EJB, e.g.

        ...
        InitialContext ic = new InitialContext();
        Object objref = ic.lookup( "java:comp/env/ejb/House" );
        houseHome = (HouseHome) PortableRemoteObject.narrow( objref,
                HouseHome.class );
        ...

The above code chunk comes from an example that I've run successfully as
part of a demo app under both Orion (successfully for the most part, that
is - there are hitches with app clients and CMP) and the J2EE RI. I store
the ref to the home in a JavaBean instance variable. The JSP sets other
search-related properties of the JavaBean using a form, which works since
the bean is associated through the <jsp:useBean> tag. On a submit action the
various instance variable values are passed, as needed, to the finder
methods invoked on the home interface reference.

Come to think of it, Java code is Java code, so perhaps the above would work
just as well inside <% ... %>. I'm going to have to give it a shot. :-)

Hope this helps.

Arved Sandstrom

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Joseph B.
Ottinger
Sent: Thursday, March 30, 2000 3:08 PM
To: Orion-Interest
Subject: Accessing EJB from JSP (again)


I'm in the process of writing a full J2EE application on the web. I'm
trying to show off the technology, and explain every step of the way,
including full source and reasons where, um, I know what the reasons are.

The URL for this nascent project
is: http://cupid.suninternet.com/phonelist/

Note that I'm learning as I go, and I'm sure to do things incorrectly. I'm
trying to be as open as I can with the entire source, so that for one
thing, reviewers can see what I'm doing wrong, and for another thing,
other J2EE application developers will be able to use this as a sort of
checklist and example project.  Feel free to review it, and make any
suggestions/feature requests you would like to. Again, the purpose is to
have a project that uses most of this technology, where appropriate, so
everyone can learn.

That said, I have run into yet another roadblock. I've got an entity bean
set up, but... how do I get a JSP page to access it? I've seen a coupel of
ways so far, but they assume I have experience in areas I don't think I
have experience in. JSP doesn't bother me; taglibs don't bother
me; implicit documentation (which is all I've found) bothers me. So here
am I, my JSP engine all revved up, and no place to go. Are there any
pointers, explained examples, people willing to walk through it with me
out there?

-----------------------------------------------------------
Joseph B. Ottinger               [EMAIL PROTECTED]
http://cupid.suninternet.com/~joeo      HOMES.COM Developer




Reply via email to