This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
What is the best way to submit objects in form through POST? I want to submit an object from a jsp page to another page. There is a submit button on the page. I found out one way is to convert the object to a string to submit. If this is possible how is it done? Example codes are most appreciated.
As the earlier post suggests - you cannot submit Java objects via HTTP form posts. Once you've displayed the results in a browser, it does not know anything about Java objects. All HTTP can do is send text - this is why Web Services (in their most common form) use XML. If it was easy to send binary encodings over standard HTTP - Web Services would be different (you'd end up with something like RMI) because binary is much more efficient than plain text.
Basically you must either uses the Session object (essentially a HashMap that maintains its values for a given user's session - where the J2EE container manages a session, usually via cookie for you automatically) OR you must persist the state yourself - for example as hidden form fields or cookies or storing in a database (where you store the record key in a cookie).
Usually people go with Session objects unless you know you're dealing with very large amounts of data in an object.
Joined: Nov 20, 2003
If I use session, I cannot determine where to remove the session object after its not used anymore. The user can click on any other links in the web application. So dont know whether its advisable to leave the session there.
If you just want your object to persist only in another page then limit your scope to "request". In that way your object will only persist per request, so you don't worry about invalidating your object. [ September 10, 2004: Message edited by: arnel nicolas ]
As I understand it (not very well ) the Base64 malarky is a way of making sure that your String (serialized Object or whatever) doesn't get whacked in transit by character encoding. Not too useful without an accompanying explanation, however.
This thread that ended up in the Java in General (Intermediate) forum may shed some light on it, particularly the posts by Mattias Arthursson and Bill Brogden.
Joined: Sep 13, 2004
Sorry for not posting a proper explanation with the code. I didn't realize it was so obscure.
Anyway, since the original intention of lin park was to pass objects through form submit, I just posted a code we use here for doing just that
Now you can use youObjectAsString and put it in a hidden or textArea to submit it through a form.