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.
Asked
Active
Viewed 1,169 times
2 Answers
2
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.

Anthony
- 12,407
- 12
- 64
- 88
-
how can I serialize an image file? in my object U have a few strings and lists and an image – Shai Zarzewski Jan 26 '13 at 11:17
-
Yes, you can uses standard [java serialization API](http://docs.oracle.com/javase/7/docs/platform/serialization/spec/serialTOC.html). 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](http://stackoverflow.com/questions/35785) – Anthony Jan 26 '13 at 12:45
0
There is one more alternative approach: use WebServices. You can get to know more about them at Apache AXIS website.

Anthony
- 12,407
- 12
- 64
- 88