• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call a Session Bean from a servlet?

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I am a new learner of EJB's. I want to develop an application which is like this..

JSP ---> Servlet----->EJB

Can u please guide me how to call a session bean from a servlet?

Thanks,
Priya Sri.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd probably be better off with

Servlet (front Controller) --> Session Bean --> back to Servlet --> forward to JSP

and you'd be better off still if you just use JavaServer Faces rather than Servlets and JSPs alone.

For code examples, it sounds like you need to get yourself a good J2EE book. Try

http://www.oreilly.com/catalog/entjbeans4/
http://www.oreilly.com/catalog/jsvrfaces/ and
http://www.oreilly.com/catalog/jvadtaobj/

cheers,

Dave
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very simple task. It looks almost identical with the way any client calls the bean, with couple of differences only:
  • When you build the initial context, you don�t need to set the environment, because your code runs on the server and it is already set.
  • You can "cast" rather then "narrowing" to get a reference to the bean�s local interface.


  • Your code will look like this:

    One more thing: this is the best approach. However you can access your bean through the remote interface, if the bean and the servlet doesn�t share the same classloader.
    Regards.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic