• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about Cookies

 
naresh kavya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I hava problem with cookies.I set cookie age as 40000 but while executing it is showing age as -1.plese provide the solutions.
Tks in advance.
cade
Cookie c1 = new Cookie("cu",cuname);
Cookie c2 = new Cookie("cp",cpwd);
c1.setMaxAge(4000000);
c2.setMaxAge(4000000);
resp.addCookie(c1); resp.addCookie(c2);
for (int i = 0; i<=cookies.length; i++)
{
c[i] = cookies[i];
name[i] = c[i].getName();
value[i] = c[i].getValue();
System.out.println("cookie age is"+c[i].getMaxAge());
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where you're creating the cookies variable.
 
naresh kavya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ben tks for response
i creted cookies as
Cookie[] c=new Cookie[10;
 
naresh kavya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and
Cookie[] cookies = request.getKookies();
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to set the cookies and read them back all within the same request cycle?
 
naresh kavya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no
i am using cookies in struts when the user enters in to page first time
2 cookies will be set in his browser memory for this i used the cookies with max age as 40000.(at the time of cookies setting i monitored the cookies age with getMaxAge().it is showing as 40000 only.)but when the user again visit the page later point of time my code is retrieving the cookies from his browsers memory .i monitored its maxage as -1.eventhough its max age is -1 application is showing that perticular users personalized data only.
 
naresh kavya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no
i am using cookies in struts when the user enters in to page first time
2 cookies will be set in his browser memory for this i used the cookies with max age as 40000.(at the time of cookies setting i monitored the cookies age with getMaxAge().it is showing as 40000 only.)but when the user again visit the page later point of time my code is retrieving the cookies from his browsers memory .i monitored its maxage as -1.eventhough its max age is -1 application is showing that perticular users personalized data only.
i hope you understand the problem
thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic