www.douglassdavis.com said:
I am having trouble getting JSP to connect to enterprise beans. what i
would like to do is to create an example showing JSP connecting to a
database via Enterprise beans, and being able to list, add, and delete
I have not been able to find one example of how to do this, and
Enterprise Beans seem very complicated.
Can any one point me to a simple explanation of how to do this? Or
tell me what steps I need to follow?
Thanks.
First, I am giving you general steps and you wont get it right the
first time. There are books written on this complex thing called EJB.
You need to read for getting a hold on them. It cannot be explained
here, so easily.
Also try to follow the books instructions, then if you have a problem,
you can post.
And I am still trying to understand what features EJB provides, and
when should you use it, and when not.
You need a class and two interfaces, say if you want a Adder bean which
adds two numbers.
AdderBean - The actual bean class containing your method, add()
Adder - The remote interface. It should contain signatures of all your
methods in the bean class, except the methods known as life cycle
methods.
AdderHome - The Home interface which actually gets the bean remote
object, via RMI.
Entries for describing the deployment go into ejb-jar.xml.
here you mention the bean name, the transaction attributes, etc.
Typically the following steps apply, when you want a handle to the
bean.
Get the JNDI initialContext. If there are initial parameters, you need
to pass the properties file for that too.
Load the home of EJB using class.forName
- Class homeClass =
Class.forname("com.mydomain.mypackageName.BeanHome");
lookup the bean name that you gave in the ejb-jar.xml(deployment
descriptor) in the JNDI initial context.
Narrow down to the BeanHome
BeanHome homeRef = (BeanHome) PortableRemoteObject.narrow(ref,
homeClass);
Get the bean remote interface.
remote = homeRef.create();
and you are ready to go.
call your methods as remote.methodname();