File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Storing objects in cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Storing objects in cookies" Watch "Storing objects in cookies" New topic

Storing objects in cookies

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Is there a way to store object level information in cookies? From what I understand cookies are limited to storing text level information. If cookies cannot store objects is there another way to store an object in a clients computer? Why would i want to do this? I want to store the objects datatype and not its value alone.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I suppose there's no reason you couldn't serialize an object to a String and then store the string in a cookie. Then, whe you retrieve the cookie, you could de-serialize the string back into an object.

Consultant, Sima Solutions
M Anderson

Joined: Mar 17, 2006
Posts: 25
Why not just stuff the object in the HttpSession? It'll be available for the duration of the session only. Unless you're expecting that data to be available forever (or, at least until the user deletes his or her cookies).

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Hmmm, I will look into serializing the object and reconstructing it. Hope it works.
I agree. Here's the link:
subject: Storing objects in cookies
It's not a secret anymore!