Hi: What is stored inside this vector that you are trying to write to the object output stream? All objects stored inside this vector should be implementing the java.io.Serialzable interface to be successfully written to a object output stream. On the same machine, its should not but it does show opposite behaviour at times.
Best Regards Sanjeev -----Original Message----- From: Zhang [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 12, 2002 9:59 PM To: [EMAIL PROTECTED] Subject: Run a applet on another PC Hi,I am a freshman on java,Could you help me. I have a servlet and a postgres data base on a solaris 8 work station. I have an applet that sends an object (a serialize class vector )to the servlet,then the servlet saves that information to the postgres data base. If I run the applet and the servlet on same work station,they work well. But if I run the applet on a another computer (PC or Unix work station). The Servlet always failed ,in geting a objectinputstream interface and catch a ERROR: <<java.io.StreamCorruptedException: Caught EOFException while reading the stream header>> I think maybe there is a delay from another computer.so when I catch the error,I try 3 time again,but I still fail. MY APPLET : public class Draw extends Applet implements ActionListener,ItemListener,MouseMotionListener,MouseListener{ Vector obj; ------------------------- try{ labtext.setText("Save Data $B!%!%!% (B"); String data="/mkalm/servlet/mkalm.mkAlm0Servlet?Savefilename="+filename.getText(); URL url=new URL(getCodeBase(),data); URLConnection con=url.openConnection(); System.out.println("SAVE CONNECT OK FILE URL Size:"+obj.size()); con.setRequestProperty("CONTENT_TYPE","application/octet-stream"); con.setUseCaches(false); con.setDoInput(true); con.setDoOutput(true); ObjectOutputStream oos=new ObjectOutputStream(con.getOutputStream()); NewVector out_vector = new NewVector((Vector)obj); oos.writeObject( out_vector ); oos.flush(); ObjectInputStream ois = new ObjectInputStream(con.getInputStream()); String answer = (String)ois.readObject(); oos.close(); ois.close(); labtext.setText(" "); } catch(Exception evt){ System.out.println("SAVE FILE URL Error"+evt); evt.printStackTrace(); } } > > ------------------------------- Servlet: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; public class mkAlm0Servlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection con = null; Statement stmt = null; PreparedStatement ps = null; ObjectInputStream ois = null; Vector vector_out = new Vector(); String ask; String almfile = new String(request.getParameter("Savefilename")); System.out.println("SAVE ALM SERVLET"); try { int flg = 0; for(int t=0;t<3;t++){ try { ois = new ObjectInputStream(request.getInputStream());//Always fail at here }catch (EOFException e) { flg = 1; System.out.println("DB Save error:" + e); }catch (StreamCorruptedException e) { flg = 2; System.out.println("DB Save error:" + e); }catch (Exception e) { System.out.println("DB Save ERRPR:"+e); }finally{ if(flg > 0){ System.out.println("DB Save Continue"); continue; } else break; } } System.out.println(" Can Read byte:" + ois.available()); NewVector in_vector = (NewVector)ois.readObject(); Vector vector_in = (Vector)in_vector.toVector(); try { Class.forName("org.postgresql.Driver"); String jdbnm = "jdbc:postgresql://192.168.0.206/" + almfile; con = DriverManager.getConnection(jdbnm, "postgres","postgres"); String pscmd = "insert into " + almfile + "( almline ) values ( ? )"; ps = con.prepareStatement( pscmd ); stmt = con.createStatement(); }catch (Exception e) { System.out.println("DB connect ERRPR:"+e); } } ------- Serialisize Class: import java.io.*; import java.util.*; public class NewVector implements Serializable { Vector data; public NewVector( Vector invector){ data = invector; } public Vector toVector(){ return data; } } ------------------- [EMAIL PROTECTED] ___________________________________________________________________________ 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 ___________________________________________________________________________ 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
