HTML can only contain character sequences. HTTP request parameters can only represent character sequences. You definitely can't pass around Java objects around. You'd need to convert them to a character sequence which uniquely represents the Java object first based on a specified format, so that it can be converted back to the Java object after retrieving it back in the server side. Character sequences are in Java represented by the String
class.
So, basically, you need to convert String[]
to String
before printing it in HTML. You can use the HTML <input type="hidden">
to represent a hidden request parameter. You need to convert the submitted String
value back to String[]
after obtaining it as HTTP request parameter. At its simplest you can choose the comma separated values (CSV) format as String
representation, or maybe XML or JSON.
A completely different alternative, for sure if the Java object is rather complex (e.g. a Javabean, possibly with more nested Javabean properties, etc) is to store the object along an unique and autogenerated key (e.g. by java.util.UUID
) in the session. Then you just have to pass exactly that unique key around as request parameter so that it can afterwards be obtained (removed) from the session based on the key.