why do you have to response.setContentType("application/x-java-serialized-object"); in the servlet, when you're going to be directly using the OutputStream to send an object to the applet ? I think your code will work pretty fine, if you remove this line from the servlet code.
regards Pramod Nair -----Original Message----- From: Jean-Baptiste Noël [mailto:[EMAIL PROTECTED] Sent: Thursday, February 27, 2003 9:16 PM To: [EMAIL PROTECTED] Subject: applet communic with servlet Hello, I include/understand or comes the error but I do not know how resolve the problem. I have applet which commnunic with a servlet. The applet sends a "string" to the servlet. The servlet receive the "string" and compares it with another. If it is not good, then the servlet re-send a "stringError". If not the servlet returns a page HTML. It is here that is the problem when the servlet returns page HTML I have the error "java.io.StreamCorruptedException: Does InputStream does not contain have serialized object" . How to make so that the applet manages the two types of objects which it receives? Is this possible? The code of the servlet and the applet below. Thank you very much. //My Applet : public class EchoApplet extends Applet { ... ... sendButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onSendData(); } } /** * Get a connection to the servlet. */ private URLConnection getServletConnection() throws MalformedURLException, IOException { URL urlServlet = new URL(getCodeBase(), "echo"); URLConnection con = urlServlet.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-java-serialized-object"); return con; } /** * Send the inputField data to the servlet and show the result in the outputField.*/ private void onSendData() { try { String log = login.getText(); // send data to the servlet URLConnection con = getServletConnection(); OutputStream outstream = con.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(outstream); oos.writeObject(log); oos.flush(); oos.close(); // receive result from servlet InputStream instr = con.getInputStream(); ObjectInputStream inputFromServlet = new ObjectInputStream (instr); String result = (String) inputFromServlet.readObject(); inputFromServlet.close(); instr.close(); // show result outputField.setText(result); } catch (Exception ex) { ex.printStackTrace(); exceptionArea.setText(ex.toString()); } } } //MY servlet public class EchoServlet extends HttpServlet { public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { try { InputStream in = request.getInputStream(); ObjectInputStream inputFromApplet = new ObjectInputStream(in); String echo = (String)inputFromApplet.readObject(); String resultToApplet; if (!(echo.equals("ok")) { response.setContentType("application/x-java-serialized-object"); resultToApplet = "Error login or password"; // echo it to the applet OutputStream outstr = response.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(outstr); oos.writeObject(resultToApplet); oos.flush(); oos.close(); } else { //my new html page response.setContentType("text/html; charset=ISO-8859-1"); PrintWriter out = response.getWriter(); out.print("<html><head></head><h1>OK</h1></html>"); } } catch (Exception e) { e.printStackTrace(); } } } ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful. Visit us at http://www.cognizant.com