1 Reply Latest reply on Nov 13, 2001 3:40 PM by tbfmicke

    How can an Applet contact an EJB?

    sanjit

      Hi,
      I want my applet in the web container to get in touch with an EJB on the Jboss application server.
      Can someone please tell me the steps involved in doing the above mentioned?
      How is the JNDI naming lookup handled?
      As of now, I have the following peace of code in the init() method of my applet and it doesnt work:
      Properties props= new Properties();
      props.put (Context.PROVIDER_URL,"localhost:1099");
      props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      InitialContext ctx = new InitialContext();
      Object objref = ctx.lookup("TraderController");
      TraderControllerHome home = ..................

      I would be grateful if somebody could shed some light on it and help me out. Thanks!
      Regards,
      Sanjit



        • 1. Re: How can an Applet contact an EJB?
          tbfmicke

          Hi

          > props.put (Context.PROVIDER_URL,"localhost:1099");

          First, you would need to use something other than localhost since that will point to the computer the applet is running on, rather than the server computer. (I assume there is something in the applet classes that gives the servers name, or at least ip address.)


          But, I think the simplest way to let a applet communicate with an EJb is to do it via a servlet. The servlet can be connected by its URL, and the applet and servlet can communicate with serialized java objects. The servlet can then do the calls to the EJB. The advantage with this is that the servlet does not need to have access to the EJB interfaces. In addition, if the applet would be running behind a firewall it would probably not be able to connect the EJBs, but able to connect to the web server.

          Regards