tags:

views:

267

answers:

3

I see many solutions for storing multiple values in one cookie in .Net and php but I have not found any good solution for Java. I dont wanna encode/decode the pair-values myself which can be risky.

A: 

The usual approach is to save a unique ID in the cookie (just a long number) and use a synchronized map in your code which gives you some data structure per ID (often another map).

Aaron Digulla
This sounds to complicated and needs some strategy when restaring the java. I just want to save a couple of name/vaule pairs.
Johannes
This is usually handled by your app server. For anything that supports servlets, just use `getSession()` to get access to such a map.
Aaron Digulla
Thx man! I thought I had to use the Cookies class, but this seems to be just what I need :) I will try it out now!
Johannes
A: 

HttpClient has soport for cookies.

PeterMmm
But this is for server side?
Johannes
As you asked for help in encode/decode, this library helps to stay in tune with the specifications. See org.apache.commons.httpclient.cookie.CookieSpecBase, Cookie.toExternalForm(), etc . This is not server/client specific.
PeterMmm
A: 

Just like Aaron said... use HttpSessions :)

Johannes