c***c 发帖数: 6234 | 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 | m******t 发帖数: 2416 | 2
[snipped]
retain
Never seen this before. Did you try to see what the cookie looks like on the
client side? Also print out all the cookies in the request, sometimes it's
just a typo in the name string...
On a side note, you might want to think twice before storing the database name
in a cookie - there might be potential security holes.
【在 c***c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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")){
|
|