How do I initiate a JNDI lookup from an applet?
Created May 7, 2012
Luigi Viggiano First, in the jar file of your applet you will need followin classes included:
The client browser must be able to open a connection to the port of where the naming service is listening (be sure about proxy settings etc.).
The client browser must have Java 2 (Java Plugin 1.2.x)
Then the code is always the same:
- Classes from the jar with the client portion of your specific jndi provider classes
- Classes from the the jar containing javax.naming standard extensions.
- Classes from the jar containing javax.rmi.PortableRemoteObject (only if the retrieved object are CORBA objecs)
- The classes you want to lookup.
The client browser must be able to open a connection to the port of where the naming service is listening (be sure about proxy settings etc.).
The client browser must have Java 2 (Java Plugin 1.2.x)
Then the code is always the same:
Properties props = new Properties(); props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ); props.setProperty("java.naming.provider.url", "codebaseurl:1099"); Context ctx = new InitialContext(props); Object ref = ctx.lookup("jndi_name");Note: it's generally avoided to use applet working on remote object, for such many difficulties and for applet security limitations, so it's better to think about applet asking services to server object thru servlets.