• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling EJB from servlet in visualage for java  RSS feed

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a newbie to java technology.
i am creating java applications using visualage for java.
I have a EJB created and tested in WTE of visualage for java(VAJ) is working fine.
I have a servlet which is also developed in VAJ is also working fine.
When i am trying to call the EJB from the servlet, it does not show any error while creating the objects of the bean.
But when i am running it, it shows a Null pointer exception.
Both the EJB and servlet are in the same package.
Please help me in get rid of this problem by providing a solution to this.
If possible please provide me the exact syntax to call a EJB from servlet through a sample code which i can run on VAJ.
Sheetal Engineer
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with VAJ. But I will suggest you few things:
When we run Servlet in J2EE application server, it runs in Web container. Similarly EJBs run in EJB container. When Servlet tries to access EJB, we need to tell Web container about the existance of EJB. This is done by using web.xml file normally. Kindly copy similar to following lines in your web.xml file:
(Copy your EJB name and Home and Remote interface names.)
The syntax for calling EJB is as follows:
//Retrieve the initial context for JNDI
Context ctx = new InitialContext();
// Narrow the reference to a ILoginEntityHome.
ILoginEntityHome home = (ILoginEntityHome)javax.rmi.PortableRemoteObject.narrow ((Object)ctx.lookup ("LoginEntity"),
// Create the remote LoginEntity bean instance and return a reference to the remote interface to this bean.
ILoginEntity remote = home.create("pqr");

You will have to obviously import related packages in your code.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!