File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes calling EJB from servlet in visualage for java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "calling EJB from servlet in visualage for java" Watch "calling EJB from servlet in visualage for java" New topic
Author

calling EJB from servlet in visualage for java

Gopal
Greenhorn

Joined: Sep 04, 2002
Posts: 7
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
Greenhorn

Joined: May 21, 2002
Posts: 4
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: calling EJB from servlet in visualage for java