由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Help Cookie getMaxAge() always return -1
相关主题
How do I send cookies from a servlet?运行servlet时出现的http status 404问题
Servlet & Cookie 求助Help! ClassCastException
有没有办法在browser第一次访问的时候知道是不是支持cookie?get full class name
理解Java Servlets [fwd]我想把一个Arraylist转成String[]
Another Servlet Problem:Browser CachingObject比较
need your comments这个是JSP的什么技术
请推荐servlet还有jsp的书java这个是什么逻辑?
servlet读取directory的基本问题新手问问这个错在哪儿?
相关话题的讨论汇总
话题: cookie话题: getmaxage话题: cc话题: always话题: database
进入Java版参与讨论
1 (共1页)
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 的大作中提到】
: 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")){

1 (共1页)
进入Java版参与讨论
相关主题
新手问问这个错在哪儿?Another Servlet Problem:Browser Caching
JAVA 一族need your comments
Re: serverlet请推荐servlet还有jsp的书
Re: how to initialize corba object orb in servletservlet读取directory的基本问题
How do I send cookies from a servlet?运行servlet时出现的http status 404问题
Servlet & Cookie 求助Help! ClassCastException
有没有办法在browser第一次访问的时候知道是不是支持cookie?get full class name
理解Java Servlets [fwd]我想把一个Arraylist转成String[]
相关话题的讨论汇总
话题: cookie话题: getmaxage话题: cc话题: always话题: database