Your jsp might be running in the same container as you bean. That's why it's able to find bean. Since the standalone client is outside the container, it needs the env variables for the container for lookup. For eg, if you are running the beans in a sun app server, you need to create your Context as :-
java.util.Hashtable env = new java.util.Hashtable(); env.putContext.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory"); env.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:3700"); Context initial = new InitialContext(env); Object obj = (Object) initial.lookup("/ejb/LoginBean");
The env properties may vary depending on your app server
[ October 27, 2004: Message edited by: Giju George ] [ October 27, 2004: Message edited by: Giju George ]
Hi , What is the reason for using this line particularly for EJB Client that is not in a container,
Cant I type cast like this directly ..
Then as you guys said i'm using the Hashtable & setting the relevant stuff , but i'm getting NamingException saying the Bean is not found. The same client was working in weblogic, After the server is migrated to oracle10g i'm facing this exception.
Cant I type cast like this directly .. code: loginHome = (LoginHome)context.lookup("java:comp/env/LoginBean");
You can safely cast the LocalHome interface but only when you 're sure it's local interface. For remote interfaces, you will need to use PortableRemoteObject.narrow(homeObject). (That's because of the IIOP protocol used)
The same client was working in weblogic, After the server is migrated to oracle10g i'm facing this exception.
Oracle uses the special ORMI protocol (instead of RMI-IIOP) which is, in my opinion, the start of a lot of problems... Anyway, the HashTable should look like: