This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes why JSP and servlet has to work differently for EJB Lookup? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "why JSP and servlet has to work differently for EJB Lookup?" Watch "why JSP and servlet has to work differently for EJB Lookup?" New topic
Author

why JSP and servlet has to work differently for EJB Lookup?

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi all,
From servlet if I want to access an EJB, I would configure ejb-ref tag in the web.xml and then use java:comp/env/ejb thing to lookup home interface of an EJB BUT with JSPs I don't think I can do it. I have to use INITIAL_CONTEXT_FACTORY and PROVIDER_URL and then I can get Remote interface access of any EJB in my JSP, right?
Why such a difference in access of an EJB if JSPs "are supposed to servlets ultimately"?
Or I am missing anything. Are there any app server vendor specific methods to use EJBs via java:comp/env/ejb from JSPs??
Regards
Maulin
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
JSPs are supposed to be views, not controllers. No?
I thought EJB 2.0+ recommended taking the factory and the URL out of the initial context fetching operation. It makes your code more container dependent. Websphere 5+ recommends just

Except when one is clustering.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by Maulin Vasavada:
Hi all,
From servlet if I want to access an EJB, I would configure ejb-ref tag in the web.xml and then use java:comp/env/ejb thing to lookup home interface of an EJB BUT with JSPs I don't think I can do it. I have to use INITIAL_CONTEXT_FACTORY and PROVIDER_URL and then I can get Remote interface access of any EJB in my JSP, right?
Why such a difference in access of an EJB if JSPs "are supposed to servlets ultimately"?
Or I am missing anything. Are there any app server vendor specific methods to use EJBs via java:comp/env/ejb from JSPs??
Regards
Maulin

You're missing something. EJB references declared in the web.xml should be accessible within JSP's as well as servlets so long as they are contained within the same web application.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Yup Kyle
I was missing that. I realized when I wrote JSP It works same way in servlets/jsp both...
Regards
Maulin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why JSP and servlet has to work differently for EJB Lookup?
 
Similar Threads
EJB# lookup() basic
About accessing EJB
Diferent ways to locate ejbs from POJOs
Lookup strings question
JNDI lookup java:comp/env/ in WSAD Test Server for P2P JMS