1

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 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how can I serialize an image file? in my object U have a few strings and lists and an image
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
0

There is one more alternative approach: use WebServices. You can get to know more about them at Apache AXIS website.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.