The advantage of using a cookie is that I can retrieve it from the HttpServletRequest object and all the processing can be done in one place. It also allows be to save a Java object directly as a string, however a cookie wasn't meant to store a lot of data so large objects might cause problems.
But, in order to store an object in a cookie it needs to be a String. To do that we serialize (the object must implement Serializable) and then base64 encode those bytes. Here is my implementation of serializing and deserializing a Java object.
And here is the reference to the original post from StackOverflow
And also for prosperity's sake, here is the prototype javascript to store values in HTML5 localStorage
It would then be enabled by calling
WorkflowFormStorage.enabled("somekey");
Also note that the javascript is not a complete solution since there are some omitted pieces of code. It is just meant to give a rough idea of one way to do it.
This comment has been removed by a blog administrator.
ReplyDelete