I think your response.setContentType is wrong if you want
to be sending java objects back and forth.

--Monte Glenn Gardner


On Thu, 5 Sep 2002, Sohaila Roberts wrote:

> Hello, I have an applet that sends an object to a servlet via an object
> input stream and I get the following error..
>
>  Ctx(/pr) : IOException in R( /pr + /servlet/pr + null) -
> java.io.StreamCorruptedException: Caught EOFException while reading the
> stream header
>         at
> java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:840)
>         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:163)
>         at pr.doGet(pr.java:43)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>         at
> org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
>         at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
>         at org.apache.tomcat.core.Handler.service(Handler.java:235)
>         at
> org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
>         at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
>         at
> 
>org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
>         at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
>         at java.lang.Thread.run(Thread.java:479)
>
> --------------------
> my code is as follows..
>
>     public boolean sendToServlet()
>     {
>         boolean sent = false;
>         FormData fd = new
> FormData(cName,deliver,phone,acct,requested,date,subt,
>                 hst,tot,items);
>         try {
>             Serializable objs[] = { fd };
>
>             URL servlet = new URL(webbase, "pr/servlet/pr");
>             in = postObjects(servlet, objs);
>             Boolean tmp = (Boolean)in.readObject();
>             sent = tmp.booleanValue();
>             in.close();
>
>         } catch(Exception e) {}
>         return sent;
>     }
>
>
>         public ObjectInputStream postObjects(URL servlet,
> Serializable objs[]) throws Exception
>         {
>                 URLConnection con = servlet.openConnection();
>                 con.setDoInput(true);
>                 con.setDoOutput(true);
>                 con.setUseCaches(false);
>                 con.setRequestProperty("Content-Type",
> "application/x-www-form-urlencoded");
>
>                 // Write the arguments as post data
>                 ObjectOutputStream out = new
> ObjectOutputStream(con.getOutputStream());
>                 int numObjects = objs.length;
>                 for (int x = 0; x < numObjects; x++) {
>                         out.writeObject(objs[x]);
>                 }
>
>                 out.flush();
>                 out.close();
>
>                 return new ObjectInputStream( con.getInputStream() );
>         }
>
> --servlet code chunk--
>
>     public void doGet(HttpServletRequest req, HttpServletResponse res)
>         throws ServletException, IOException
>     {
>         res.setContentType("text/html");
>         ObjectInputStream in = new
> ObjectInputStream(req.getInputStream());
>         try {
>             FormData data = (FormData)in.readObject();
>             PrintWriter out = res.getWriter();
>             report(res.getWriter(), data);
>
>         } catch(Exception e) {}
>     }
>
>
> -----------------
> In a previous application I used basically the same code but in my servlet
> I used the doPost method instead. That application worked fine with no
> errors..  When I tried doing this appliation with doPost I would get
> GET method not specified errors..
>
> The only difference between the 2 applications is that I am now using
> tomcat (not servletrunner).
> Is there something I'm not doing that I should be?
>
> Thanks
> Sohaila
>
> ___________________________________________________________________________
> 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

Reply via email to