Hello,

I am successfully doing this, sending objects between an applet and a
servlet. I think your problem is that you call connect() before writing to
the output stream. Try putting the connect after you finish writing to the
connections output stream. This seems somewhat counter intuitive but the
output is actually sent as part of the connection process.

Here's my working code:

        URLConnection urlConnection = (new
URL(serverURLString)).openConnection();

        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.setRequestProperty ("Content-Type",
"application/octet-stream");
        urlConnection.setAllowUserInteraction(false);
        urlConnection.setUseCaches(false);

        ObjectOutputStream oos = new
ObjectOutputStream(urlConnection.getOutputStream());
        oos.writeObject(request);
        oos.close();

        urlConnection.connect();  <------------ connect only after writing
complete!!

        ObjectInputStream ois = new
ObjectInputStream(urlConnection.getInputStream());
        Object replyObject = ois.readObject();


Hope this helps,

Rob Griffin
[EMAIL PROTECTED]
Quest Software Pty Ltd
303 High St, Ashburton, Vic. 3147 Australia
http://www.quests.com


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Manavalan, EzhilX
[snip]
>
> Hi Damodara ,
> I'm getting the same IOException when I tried your code.
> Can you please help me out if you have done this b4.
> Thanks is advance.
>
>
> -----Original Message-----
> From: Damodara Muppala [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 13, 1999 12:22 PM
[snip]
>
> try using this approach: it should work
>
>
>            try {
>               action = new URL(ss);
>               url = action.openConnection();
>               url.setDoInput(true);
>               url.setDoOutput(true);
>               url.setUseCaches(false);
>               ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
>
> url.setRequestProperty("Content-Type","application/octet-stream");
>               out = new ObjectOutputStream(byteOut);
>               out.writeObject(obj);
>               out.flush();
>               byte[] buf=byteOut.toByteArray();
>               url.setRequestProperty("Content-length"," "+buf.length);
>               DataOutputStream  servletOut = new
> DataOutputStream(url.getOutputStream());
>               servletOut.write(buf);
>               servletOut.close();
>            }
>          catch(MalformedURLException me) {
>
>               System.out.println("MalformedURLException");
>          }
>          catch (IOException ee) {
>             System.out.println("IOException");
>           }
>
>             try {
>                   in=new ObjectInputStream(url.getInputStream());
>                   ht = (Hashtable)in.readObject();
>                   in.close();
>                }
>            }
>            catch (Exception e) {
>            }
>
[snip]

___________________________________________________________________________
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