You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Qian <Da...@accrue.com> on 2000/05/08 03:23:44 UTC

Problem on Applet to Servlet communication ?

Hi, everyone:

I am working on a program that an applet communicates with a servlet.
I did the exact what the book (Developing Java Servlet) and the paper by
Chad Darby
said.  My applet will send object to the servlet.  My serlvet will not send
information to the applet.
I can not make applet-servlet communication working.

The following are applet codes:

URL url = new
URL("http://bird/examples/servlet/com.accrue.etel.attribute.AttributeServlet
");

      URLConnection urlCon = url.openConnection();
      urlCon.setDoOutput(true);
      urlCon.setDoInput(true);
      urlCon.setUseCaches(false);
      urlCon.setRequestProperty("CONTENT-TYPE", "application/octet-stream");

      ObjectOutputStream os = new
ObjectOutputStream(urlCon.getOutputStream());
      os.writeObject(itemSelected);
      os.flush();
      os.close();

      ObjectInputStream is = new ObjectInputStream(urlCon.getInputStream());
      AttrSelectorBean attributeBeanRead = null;
      attributeBeanRead = ( AttrSelectorBean) is.readObject();
      is.close();
    }
    catch (IOException e) {
      System.err.println(e.getMessage());
    }
    catch(ClassNotFoundException ce) {
      System.err.println(ce.getMessage());
    }
  }

The following are codes in servlet that relate to applet-servlet
communication.

 ois = new ObjectInputStream(request.getInputStream());
      beanFromApplet = (AttrSelectorBean) ois.readObject();
      ois.close();

Any help will be greatly appereciately !

David