Help Cookie getMaxAge() always return -1# Java - 爪哇娇娃
c*c
1 楼
Friends,
I wrote a servlet and wanted to save some info in cookie.
Cookie c = new Cookie("database", myObj.getDbName());
c.setMaxAge(10000);
response.addCookie(c);
Cookie cc[] = request.getCookies();
if(cc != null){
for(int i=0; i< cc.length && !found; i++){
if(cc[i].getName().equals("database")){
int t = cc[i].getMaxAge();
}
}
}
t is always -1. But c's max age is 10000. So in next login, web can not retain
dbname for me.
Anyboday met the sim
I wrote a servlet and wanted to save some info in cookie.
Cookie c = new Cookie("database", myObj.getDbName());
c.setMaxAge(10000);
response.addCookie(c);
Cookie cc[] = request.getCookies();
if(cc != null){
for(int i=0; i< cc.length && !found; i++){
if(cc[i].getName().equals("database")){
int t = cc[i].getMaxAge();
}
}
}
t is always -1. But c's max age is 10000. So in next login, web can not retain
dbname for me.
Anyboday met the sim