Serialize any Serializable with a byte array
Yes.
and enter the line.
No.
For exact statements, see below.
os = new ObjectOutputStream(new ByteArrayOutputStream()); os.writeObject(o); s = os.toString(); // s = Base64.encode(s);//Need this some base 64 impl like Apache ? s = URLEncoder.encode(s, "UTF-8");
These statements do not even do what you have described, which is wrong in any case. OutputStream.toString() does not turn bytes into strings, it just returns a unique identifier for the object.
Base64 output with number 1.
The base64 output should use a byte array as input, not a string. A string is not a container for binary data. See the corrected code below.
ByteArrayOutputStream baos = new ByteArrayOutputStream(); os = new ObjectOutputStream(baos); os.writeObject(o); os.close(); s = Base64.encode(baos.toByeArray());
This at least fulfills your task.
Is base 64 required or can skip step 2?
If you want String, you must somehow encode it.
Use java.util.URLEncode.encode to encode a string
This is only necessary if you send it as a GET or POST parameter.
Use apache http components or URL class to send from servlet 1 to 2 after naming
Yes.
In Servlet 2, the J2EE structure already had URLDecoded, now it simply performs the reverse steps and throws the object according to the parameter name.
Yes, but remember to go directly from the base64 encoded string to an array of bytes, without an intermediate string.
Basically looking for the fastest and most convenient way to send objects between JVMs.
These goals are not always compatible. The most convenient these days are probably XML or JSON, but I doubt they are faster than serialization.
os = null;
Setting links that are about to go out of scope to null is pointless.
HttpParam p = new HttpParam ("bean1", s);
It is possible that HttpParam is doing URLEncoding for you. Check this.