Redian新闻
>
Help Cookie getMaxAge() always return -1
avatar
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
avatar
m*t
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 的大作中提到】
: 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")){

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。