jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes I meet a problem. It is very interesting!!!!!!!!!!!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "I meet a problem. It is very interesting!!!!!!!!!!!!!!!!" Watch "I meet a problem. It is very interesting!!!!!!!!!!!!!!!!" New topic

I meet a problem. It is very interesting!!!!!!!!!!!!!!!!

Geoffrey Ren

Joined: Nov 25, 2002
Posts: 18
my applet interact with the webserver by HTTP protocol. I need to get a object from server.
But when I used the ObjectInputStream object readObject method. It throw a exception:
Server code:
ObjectOutputStream objout = new ObjectOutputStream(response.getOutputStream());

if (result.size() > 0)
for (int i = 0; i < result.size(); i++)
Lesson lesson = new Lesson();
It is right.
Client code:
ObjectInputStream read = new ObjectInputStream(socket.getInputStream());

System.out.println("Get the outputing object2");

Vector result = new Vector();
Lesson lesson = null;
while ((lesson = (Lesson)read.readObject()) != null)
socket.close ();
It meet problem:
The exception:
java.io.StreamCorruptedException: InputStream does not contain a serialized object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:849)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at test.TestGet.main(TestGet.java:56)
HTTP/1.0 200 OK
Date: Wed, 05 Mar 2003 13:57:00 GMT
Server: WebLogic WebLogic Server 7.0 Thu Apr 25 17:16:22 PDT 2002 180709
Content-Type: application/octet-stream
Connection: Close
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
What is in result.get(i)? Is it a serializable object?
[ March 05, 2003: Message edited by: Paul Stevens ]
Geoffrey Ren

Joined: Nov 25, 2002
Posts: 18
It is class which implements the Serializable interface.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

What's so Interesting!!! about that?

GenRocket - Experts at Building Test Data
Geoffrey Ren

Joined: Nov 25, 2002
Posts: 18
I think this problem is very monstrosity. I resarched all of material. I can't find any key.
I wanted superior can help me settle the problem. Our project will be end. I will very malformation if this problem can't be settled.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You need to show more code in the handling of your socket variable... You might be trying to deserialize the response itself, rather than the octet stream in the response body...

Of course, you may get more help on this topic by posting it to the Servlets forum instead of the Swing/JFC/AWT forum... Don't worry... I'll move it for you...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13018

Just for fun - try setting the content type and all other headers before getting the OuputStream and lets see if that makes a difference. Also, where does "socket" in the following come from?

You should be using a URLConnection on the applet side and getting the input stream from that.
I agree. Here's the link: http://aspose.com/file-tools
subject: I meet a problem. It is very interesting!!!!!!!!!!!!!!!!
It's not a secret anymore!