Kavitha,
You have stumbled across a very common problem, the solution to which
isn't at all obvious.
Insert the code noted below. You would expect the URLConnection class to
do this for you but it doesn't.
Hope this helps,
Rob Griffin
Quest Software
E-mail: [EMAIL PROTECTED]
Web site: http://www.quest.com
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> kavitha ramasamy
> Sent: Wednesday, 17 May 2000 23:07
> To: [EMAIL PROTECTED]
> Subject: Re: Applet to Servlet Communication Exception
>
>
> Hello,
>
> My applet code is
>
> URL servlet = new URL(servletName);
> URLConnection con = servlet.openConnection();
> con.setDoInput(true);
> con.setDoOutput(true);
> con.setUseCaches(false);
> con.setDefaultUseCaches(false);
> System.out.println("after connection");
> con.setRequestProperty("Content-type", "application/octet-stream");
> // Send the request object to the server
> System.out.println("SQL = " + sSQL );
> toServlet = new ObjectOutputStream(con.getOutputStream());
> toServlet.writeObject(sSQL);
> System.out.println("after write object");
> toServlet.flush();
> toServlet.close();
con.connect(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< insert this here
> toServlet = null;
> // Read the input from the host
> objStream = new ObjectInputStream(con.getInputStream());
> if( objStream == null) {
> return;
> }
>
> Thanks,
> kavitha
>
> >From: Rob Griffin <[EMAIL PROTECTED]>
> >Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> > Servlet API Technology." <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: Applet to Servlet Communication Exception
> >Date: Wed, 17 May 2000 09:04:56 +1000
> >
> >Kavitha,
> >
> >You need to post your applet code as well because the problem
> >might be at that end. Just the code that sends the object.
> >
> >Rob Griffin
> >Quest Software
> >
> >E-mail: [EMAIL PROTECTED]
> >Web site: http://www.quest.com
> >
> > > -----Original Message-----
> > > From: A mailing list for discussion about Sun Microsystem's
> Java Servlet
> > > API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> > > kavitha ramasamy
> > > Sent: Tuesday, 16 May 2000 22:24
> > > To: [EMAIL PROTECTED]
> > > Subject: Applet to Servlet Communication Exception
> > >
> > >
> > > Hello ,
> > >
> > > I am trying to make a applet to servlet communication. The
> > > applet makes a
> > > connection but servlet produces the following exception.
> > >
> > > My code is
> > >
> > > public void doPost(HttpServletRequest request,
> > > HttpServletResponse response)
> > > throws ServletException, IOException {
> > >
> > > ObjectOutputStream out = null;
> > > Connection con = null;
> > > System.out.println("Started the DataSetServlet..."+request);
> > > try {
> > > / Retrieve the service request
> > > System.out.println("getting the stream");
> > > InputStream ins = request.getInputStream();
> > > System.out.println("Creating the stream "+ins);
> > > //getting exception at this line
> > > ObjectInputStream in = new ObjectInputStream(ins);
> > > System.out.println("Reading the object");
> > >
> > > String sSQL = (String) in.readObject();
> > > in.close(); in = null;
> > >
> > >
> > >
> > >
> > > Creating the stream SaApi.servlet.SaServletInputStream@8b3a61cb
> > >
> > > Exception: Caught EOFException while reading the stream header
> > > java.io.StreamCorruptedException: Caught EOFException while
> reading the
> > > stream h
> > > eader
> > > at
> > > java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:727
> > > )
> > > at
> java.io.ObjectInputStream.<init>(ObjectInputStream.java:165)
> > > at SaServletEngine.DataSetServlet.doPost(Compiled Code)
> > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
> > > at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
> > > at
> > > SaApi.servlet.SaServletUtils.serviceRequest(SaServletUtils.java:532)
> > > at
> > > SaApi.servlet.SaServletUtils.processServletRequest(SaServletUtils.jav
> > > a:633)
> > > at
> > > SaApi.servlet.SaServletInvokerApp.SaProcessInputStream(SaServletInvok
> > > erApp.java:159)
> > > at
> > > SaApi.servlet.SaServletInvokerApp.handleClient(SaServletInvokerApp.ja
> > > va:226)
> > > at SaApi.SaApp.processRequest(Compiled Code)
> > > at
> > > SaApi.SaSamUbsContext.processActivator(SaSamUbsContext.java:1046)
> > > at
> >SaApi.SaSamUbsContext.processRequest(SaSamUbsContext.java:1383)
> > > at SaApi.SaSamUbsContext.execute(SaSamUbsContext.java:1487)
> > > at SaApi.SaThreadPool$Worker.run(Compiled Code)
> > > at java.lang.Thread.run(Thread.java:479)
> > > Closed the object stream ...
> > >
> > > Any help is really appreceated.
> > >
> > > Thanks,
> > > Kavitha.
> > >
> >
> >_________________________________________________________________
> __________
> >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
>
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
> __________________________________________________________________
> _________
> 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