Web tier: servlets, JSP, Web frameworks: Applet to servlet communication
Hello. I want to know about how to write program on applet
- Posted by: Nishant Jindal
- Posted on: October 25 2000 07:55 EDT
to servlet communication.please give example also.
Thanks in advance
- Applet to servlet communication by Anonimous Anonimous on October 25 2000 11:17 EDT
- Applet to servlet communication by Marty Mersinger on October 26 2000 09:54 EDT
- Applet to servlet communication by Sohail Sikora on October 27 2000 17:16 EDT
- Re: Applet to servlet communication by J Dev on September 09 2007 03:19 EDT
- Re: Applet to servlet communication by J Dev on September 25 2008 10:05 EDT
You have to send a HTTP request from the applet to the servlet. It is looks like obtaining any HTML page from the applet. So, if you want to send parameters to servlet by GET method, use URLConnection class. If you wish to use POST method, probably, created the request manualy and sent it through Socket, port 80. But somethere may exist some more convenient classes.
The book by Marty Hall, Core Servlets and JavaServer Pages (JSP), has an example with code on how to do Applet to Servlet communication. Should have what you are looking for.
Try to get the book JAVA Servlet programming by Jason Hunter. It has the example that you need. You can also look at the O Reilly website at www.oreilly.com
it has applet-servlet example
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 http://www.jyog.com