Skip to Content
author's profile photo Former Member
Former Member

Not able to make a JNDI look up for an EJB from a Servlet


I have J2EE Enterprise Application containing an EJB module and an webmodule.

EJB module has one Stateless Session Bean.

Web Module has one Servlet (try to invoke the Stateless Session Bean.)

I have made the JNDI look up in the following way:


Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, "");

env.put(Context.PROVIDER_URL, "localhost:50004");

Context cxt =new InitialContext(env);

Object obj = cxt.lookup("Sample2/ReadConfigBean"); beanHome =( obj,;


But at the part of PortableRemoteObject.narrow it is retruning me the beanHome as NULL.

And also I observed that the "cxt.lookup(s);" is returning and object of type class

Could any one put light on this. why it is happening like this.

I have verified the JNDI look up string.

Thanks for your time and help.


Ravi prasad

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2005 at 03:44 AM

    Hi Ravi,

    Looks like you are using an incorrect JNDI lookup path that's why it couldn't return the object. You can check the JNDI lookup path of your EJB from the Visual Admin. Go to the EJB Container service and drill down to your EJB for the JNDI name. You should lookup using this path instead.

    BTW, since your Web module and EJB module are in the same application, you can just lookup the EJB from your Servlet without providing the context, just a FYI.



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 10, 2005 at 06:04 PM

    Hi Ravi,

    the returned UnsatisfiedReferenceImpl merely indicates that the lookup object cannot be found.

    As we had a personal mail correspondence I copy my explanation here to reveal it to the rest. Here it is:

    The problem I see in the listed code is the way you obtain the InitialContext. According to the specification your servlet obtains its JNDI environment by Context cxt =new InitialContext();

    A problem might also be a missing ejb-ref declaration in the web.xml. You have to declare an ejb-ref in order to lookup an EJB

    A hint: You might list the whole naming tree using the “lsn” shell command (first you must activate it by “add naming”).



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.