communication between servlet and applet


Web tier: servlets, JSP, Web frameworks: communication between servlet and applet

  1. Sir,

      Can anybody help me how to contact an particular servlet from its corresponding applet and to pass the applet parameters to the servlet.

  2. Dear Murali,

    Go to the Link ""

    rajeevsmcp at usa dot net
  3. See the O'reily SERVLETS ....Comunication between Applet and Servlet

  4. There is an excellent article at

    It mainly refers to RMI but you can find what you ask for with minor modifications.
    The main idea is that you create a stream between servlet and applet and you use Serialization for the communication.
  5. how to compile and run[ Go to top ]

    respected sir/mam

    kindly help me out how to compile and run the servler and have the link btn the html and servlet.
  6. Here is the code which you can use to communication between applet and servlet/JSP following code can be used at applet side : /* *URL to servlet */ URL serverURL = new URL(servletPath); URLConnection connection = serverURL.openConnection(); /* * Connection will be used for both input and output */ connection.setDoInput(true); connection.setDoOutput(true); /* * Disable caching */ connection.setUseCaches(false); /* *connection will be used for transfaring serialized java objects. */ connection.setRequestProperty("Content-Type", "application/octet-stream"); ObjectOutputStream outputStream = new ObjectOutputStream(connection.getOutputStream()); outputStream.writeObject(request); outputStream.flush(); outputStream.close(); ObjectInputStream inputStream = new ObjectInputStream(connection.getInputStream()); response = (Map)inputStream.readObject(); inputStream.close(); Here response is the response Map returned from servlet. following code can be used in your servlet to send serializable objects to applet. write this code in doXXX method of servlet. ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream()); Map responseMap = new HashMap(); /* put watever objects you wants to return to applet. This objects must be serializable. responseMap.put("a", "a"); */ out.writeObject(responseMap); out.flush(); out.close(); response.setStatus(HttpServletResponse.SC_NO_CONTENT); SS
  7. See Applet Servlet Communication Example