• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling EJB from servlet in visualage for java

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
<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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic