This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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: <ejb-ref> <ejb-ref-name>LoginEntity</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.abc.project.login.ejb.ILoginEntityHome</home> <remote>com.abc.project.login.ejb.ILoginEntity</remote> </ejb-ref> (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"), ILoginEntityHome.class); // 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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: calling EJB from servlet in visualage for java