set values in cookies ?

Hello Friends

m using cookies in jsp

i want to store startMonth and endMonth fields data in cookies

so for startDate m using

"Cookie ck=new Cookie("startmonth",request.getParameter("startMonth"));

response.addCookie(ck);"

but i wana store endDate also in cookie so what is the way to store

it in cookies

m using

"Cookie ck1=new Cookie("startMonth",request.getParameter("startMonth"));

response.addCookie(ck1);"

"Cookie ck2=new Cookie("endMonth",request.getParameter("endMonth"));

response.addCookie(ck2);"

is this the proper way to create two cookies objects for stoaring two values in cookies

if yes then what if i wana store 10 values in cookies

[748 byte] By [SwapnaliDashratha] at [2007-11-27 6:00:36]
# 1
There are several ways of maintaining those values.2 main solutions comes to mind:1) Put them in an array (use field delimiters).2) Put an unique ID in the cookie and maintain a backing map of objects with the unique ID as key.
BalusCa at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks For The Replybuthav i used wrong way,n will u plz explain in some detail how can i use array in that n which is the Professional way to haddle such situation
SwapnaliDashratha at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Whatever u r doing is right

so u can use muliple value in cookies by following way

<%

Cookie strtMonth=new Cookie("startmonth",request.getParameter("stMonth"));

strtMonth.setMaxAge(30*60);

Cookie strtYr=new Cookie("startyr",request.getParameter("minyear"));

strtYr.setMaxAge(30*60);

Cookie EnMonth=new Cookie("endmonth",request.getParameter("endMonth"));

EnMonth.setMaxAge(30*60);

Cookie EnYr=new Cookie("endyr",request.getParameter("maxyear"));

EnYr.setMaxAge(30*60);

response.addCookie(strtMonth);

response.addCookie(strtYr);

response.addCookie(EnMonth);

response.addCookie(EnYr);

%>

amol_0008@rediffmail.coma at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Whatever u r doing is right

just use following code to set multiple value in cookies

<%

Cookie strtMonth=new Cookie("startmonth",request.getParameter("stMonth"));

strtMonth.setMaxAge(30*60);

Cookie strtYr=new Cookie("startyr",request.getParameter("minyear"));

strtYr.setMaxAge(30*60);

Cookie EnMonth=new Cookie("endmonth",request.getParameter("endMonth"));

EnMonth.setMaxAge(30*60);

Cookie EnYr=new Cookie("endyr",request.getParameter("maxyear"));

EnYr.setMaxAge(30*60);

response.addCookie(strtMonth);

response.addCookie(strtYr);

response.addCookie(EnMonth);

response.addCookie(EnYr);

%>

amol_0008@rediffmail.coma at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanks Amol !!! thanks for reply !! i have used following code and it really works
SwapnaliDashratha at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Personally I don't find it professional to flood the client with a lot of cookies, while the data can be easily stored serverside. Just gently use cookies to identify the client, not to save the client data.
BalusCa at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hi BalusC

ya u are absolutly right,that we shud not play with clients data.

but with my client, scenario is he wants his last selected start date and EndDate on every Reports as default report date value for 8 days.

that why m using cookie to set default date value as last selected dates

so is that a right way?

waiting

SwapnaliDashratha at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Hi BalusC

ya u are absolutly right,that we shud not play with clients data.

but with my client, scenario is he wants his last selected start date and EndDate on every Reports as default report date value for 8 days.

that why m using cookie to set default date value as last selected dates

so is that a right way?

waiting

SwapnaliDashratha at 2007-7-12 16:39:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...