How can I obtain a JNDI Context from inside an applet?

John Zukowski

To get an initial context from an applet, you need to pass the InitialContext constructor a Hashtable with the Context.APPLET property ("java.naming.applet") set:

Hashtable hash = new Hashtable()
// this is a reference to the applet
hash.put(Context.APPLET, this);
Context ctx = new InitialContext(hash);
The following JNDI parameters would then be read from the APPLET parameters:
  • java.naming.factory.initial
  • java.naming.factory.object
  • java.naming.factory.state
  • java.naming.factory.control
  • java.naming.factory.url.pkgs
  • java.naming.provider.url
  • java.naming.dns.url
as in