I used JBOSS3.2.1 integrate Jetty and I want to write a JSP page that call CMP EJB. But I don't know how to config JBOSS to do this.
Can anyone tell me step by step(because I'm a beginer J2EE) how to config JSP call EJB in JBOSS with Jetty.
Thanks a lot!
First of all write your entity bean and make sure it is correct, then you should package your bean in jar file and put a deployment descritopr [ejb-jar.xml] for it, then you should bind your bean to jndi tree in jboss you can do this in jboss.xml, you should put it beside your ejb-jar.xml
the syntax that you should use in jboss.xml is :
after that you should write your web tier code ,
you should get an InitialContext object , and lookup your entity bean's jndi name . so at this point you have all the gates to your entiy . have fun now.
if you have problems , let me know , i will give you more detailed instructions.
While you get up to speed on EJB authoring, you may prefer to write a test stub in plain Java that exercises your CMP EJB. Once that works, migrate the client code into your JSP. In other words break up your task into two discrete steps.
Here is some code for a JBOSS3.2.1 CMP EJB lookup that you can use as a template:
public static void main(String args)
Hashtable env = new Hashtable();
// Enclosing the whole process in a single `try' block is not an ideal way
// to do exception handling, but I don't want to clutter the program up
// with catch blocks
// Get a naming context
InitialContext jndiContext = new InitialContext(env);
// Get a reference to the Bean
Object ref = jndiContext.lookup("Contact");
// Get a reference from this to the Bean's Home interface
ContactHome home = (ContactHome)
// Create an object from the Home interface
Contact contact= home.create();
// Call remote methods
String retval = contact.getName();
Thanks for your help!
I still have a question.
If I call EJB from client with JavaApp( not JSP) I must have some
interface e.g: HomeInterface , a Interface which extends EJBObject.
And I run my program successful.
But JSP Page which call EJB is on server(run JBOSS with Jetty).
Where do I put class interface in JBOSS for my JSP Page use it?
Thank you very much!