开发者

manage form data with cookies and servlets

I've been checking info about cookies data persistence and retrival. it seems that cookies can only manage key value pairs, i want to store data from a form (like name, desc开发者_C百科ription, age, number, gender, etc). Is this possible? i saw some examples with javascript but i am not very sure about that.

I'm using spring mvc 2.5, it allows me to access HttpSeesion, HttpServletRequest and HttpServletResponse.

I have already done some exercises retriving and storing a value.

I want to try this way because at this moment the data comming from forms are handled by session. and not always the session is cleaned up.


Storing large and/or user-sensitive data in a cookie is a poor practice. Cookies are fully exposed into public and they have huge limitations as to the available storage space.

Rather autogenerate a long, unique and near-impossible-to-bruteforce ID (java.util.UUID is helpful in this), store it in a cookie. Finally use this ID as key in a Map or a SQL database in the server side where you store the data. This way you will be able to associate the desired data with the ID as found in the cookie.


Update as per the comments, your concern turns out to be the server memory usage (I initially understood that it was the session lifetime being too short). The first paragraph of the answer still stands: You really don't want to do that. This is a security hole and the cookie space is very limited.

As to the actual concern: just give your server more memory, or configure it to store sessions on disk, or just manually store the data in a DB along a key in session scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜