This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup Kyle
I was missing that. I realized when I wrote JSP It works same way in servlets/jsp both...
Regards
Maulin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic