ObjectStream communication between servlet and rich client

Hi,

I need to send multiple objects from a servlet to a rich client.

Is it possible to send 2 objects of different types at the same time - ie, a hashtable and a custom object by writing them one after another into the response's ObjectOutputStream?

Also, if I have two vectors containing different object types, say a Vector of Strings and a Vector of custom objects, how do I read the ObjectStream at the client end to get these two objects? Do I read two Vectors from the ObjectInputStream and then check the contained object using instanceOf?

In the above scenarios, is it better to wrap the entire set of objects with a serialized wrapper class and send that single object from the server to the client?

Please advice. Thanks in advance!

[782 byte] By [sreegaua] at [2007-10-3 2:26:10]
# 1

You can send any number of objects in a stream one after other. If they are in different types/classes then you have to be carefull when casting to the specific types at the other end becouse if you try to cast to wrong type you get a runtime exception.

Normally when you receive the objects you will know in advande (programming time) which vector comes first in the stream so you can treat them acordingly.

Since both of them are vectors you can cast them to vector references at the read end and can tread the elements of the first vectors as strings and the elements of the other vectors as something else provided that the client always send the string vector first.

Whether to make it a single object or ot is a design decision that you have to make. It it make sence to put those two vectors together(logically related) then its better to do so.

LRMKa at 2007-7-14 19:25:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...