File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
Author

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

Geoffrey Ren
Greenhorn

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());
response.setContentType("application/octet-stream");

if (result.size() > 0)
{
for (int i = 0; i < result.size(); i++)
{
objout.reset();
objout.writeObject(result.get(i));
objout.flush();
}
}
else
{
Lesson lesson = new Lesson();
objout.writeObject(lesson);
objout.flush();
}
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)
{
result.add(lesson);
}
writer.close();
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
Greenhorn

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: 15299
    
    6

What's so Interesting!!! about that?


GenRocket - Experts at Building Test Data
Geoffrey Ren
Greenhorn

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.
Thanks!!
Nathan Pruett
Bartender

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...


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

Joined: Mar 22, 2000
Posts: 12769
    
    5

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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I meet a problem. It is very interesting!!!!!!!!!!!!!!!!