I have a client-server program that are using servlets to communicate with each other, each of them is sending an object (of a class that I defined) to the other. Can I send it directly using the setContentType(myClass) in the servlet? Or do I need to something completely different? I couldn't find a way to do it.
2 Answers
You need to serialize the object at server side, send it as an array of bytes, or encoded as a text (using base64 for example), and than deserialize it at the client side.
2 Comments
Shai Zarzewski
how can I serialize an image file? in my object U have a few strings and lists and an image
Anthony
Yes, you can uses standard java serialization API. But this will only work if client and server has equal JRE version. In case you need support for different versions of JRE, you can serialize to XML
There is one more alternative approach: use WebServices. You can get to know more about them at Apache AXIS website.