This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Different results from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Different results from servlet" Watch "Different results from servlet" New topic
Author

Different results from servlet

seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi
I'm opening a URLConnection and writing a simple string to a servlet.In the servlet when I try to read it using readObject, I get
java.io.StreamCorruptedException
Version Mismatch,
Expected 5 and got 2
This happens only when I run the program from my machine in office. When I try the same thing from my home pc, it works fine. In both cases the servlet was running on the same remote server. Could someone think of any reason for this difference in behaviour ?
Thanx in advance
seema


Sun Certified Java Programmer<br />Sun Certified Web Component Developer<br />Sun Certified Business Component Developer
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
why dont you add it as a parameter? if you send it using the object serialization you will get version mismatch if the JDK has been tweaked ( I think). Basically the class version will cause a deserialization failure http://stein.cshl.org/jade/distrib/docs/java.io.ObjectInputStream.html
if there is a version mismatch and because String is treated as an object if you get object, this will be checked for. I guess its sort of a bug since a version mismatch in a string should cause any deserialization problems and so the handlers should account for that.
Since it's just a string, is there not a better way to do it?


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi thanks a lot for the reply. Actually the object written to the servlet may not always be a String. It could be a Vector or a Hashtable depending on some conditions. Thats why I used readObject and writeObject thinking that this would work in all cases. If it was a String, I would have passed it as parameter itself as you suggested. Is there any other way to get around this problem ? My whole project depends on this.
Thanks again
Seema
chanoch wiggers
Author
Ranch Hand

Joined: May 24, 2001
Posts: 245
I think you could get around it by subclassing the classes you will need to pass and in each case implementing a readObject that doesnt check the version information.
the only problem is... string is final so I am not sure how you would get around that - I am finding it hard to believe that this is the problem because surely they wouldnt have done this to themselves? Anyway, a string is internally stored as an array of characters so you could implement a class that does that for serialization and deserialization.
Can I ask what the jdk versions on the two machines are?
seema mani
Ranch Hand

Joined: Sep 30, 2001
Posts: 49
hi thanks. I'll try this way. About the JDK versions, the server is on JDK1.3.1 and the client on JDK1.2.2

Thank you
Seema
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Don't forget that there are other ways to serialize objects, even complex ones. Serialization/desierialization is such a common issue that lots of clever people have solutions for it. Look at "hessian" and "burlap" from http://www.caucho.com/ , for example.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Different results from servlet
 
Similar Threads
depolying servlet on weblogic server domain
EJB 3.0 Annotation giving problem with servlets
Help! DriverManager.getConnection problem
Accessing EJB on websphere 3.5 from Java Client
Naming exception : running out of time pleae help