A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
EJB and other Java EE Technologies
How to call a Session Bean from a servlet?
Joined: Mar 30, 2004
Mar 11, 2005 07:06:00
I am a new learner of
's. I want to develop an application which is like this..
Can u please guide me how to call a session bean from a
Joined: Feb 16, 2005
Mar 11, 2005 12:58:00
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
and JSPs alone.
For code examples, it sounds like you need to get yourself a good
Dave Clark<br />Senior WebSphere Architect<br /><a href="http://www.versant.com" target="_blank" rel="nofollow">Versant Open Access - JDO2 & EJB3</a>
Joined: Feb 17, 2005
Mar 11, 2005 13:02:00
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:
InitialContext initCtx = new InitialContext(); MyBeanLocalHome home = (MyBeanLocalHome)initCtx.lookup("java:comp/env/ejb/MyBeanJndiName");
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.
I think, therefore I exist -- Rene Descartes
I agree. Here's the link:
subject: How to call a Session Bean from a servlet?
Manage session between servlet and session ejb
local interface vs remoter interface.
Manage session between servlet and session bean
using session facade pattern to call entity bean
How to maintain session info between a servlet and a session bean
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013