cookie的一些基本操作
2007-11-22 12:09
309 查看
//写cookie
Cookie usernamecookie = new Cookie("username",username);
Cookie passwordcookie = new Cookie("password",password);
//生命周期
usernamecookie.setMaxAge(60*60*24*365);
passwordcookie.setMaxAge(60*60*24*365);
response.addCookie(usernamecookie);
response.addCookie(passwordcookie);
//读cookie
for (int i = 0; i < cookies.length; i++)
...{
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("username"))
...{
username = c.getValue();
}
else if(c.getName().equalsIgnoreCase("password"))
...{
password = c.getValue();
}
}
//删除cookie
Cookie[] cookies=request.getCookies();
if(cookies!=null)
...{
for(int i=0;i<cookies.length;i++)
...{
String tempuid_1=cookies[i].getName();
if(tempuid_1.equals("username"))
...{
cookies[i].setMaxAge(0);
response.addCookie(cookies[i]);
}
if(tempuid_1.equals("password"))
...{
cookies[i].setMaxAge(0);
response.addCookie(cookies[i]);
}
}
}
相关文章推荐
- Session和Cookie的一些基本操作
- git hub的一些基本操作
- QT一些基本的操作(文件、图片等)
- linux 下mysql一些基本操作
- 文件的一些基本操作
- c# 读取写入excel单元格(包括对excel的一些基本操作)
- visio的一些基本操作(附visio2007破解码)
- 一些VC对计算机基本功能操作
- MYSQL的一些基本操作指令
- CodeIgniter的中的一些基本数据库操作的demo
- Oracle 11g 发行版2 新安装后关于登录的一些基本操作
- R的一些基本操作
- 循环双链表的插入和删除的一些基本操作java版
- C#操作word的一些基本方法(word打印,插入文件,插入图片,定位页眉页脚,去掉横线)
- C#数据库的一些基本操作 第一篇
- Java 中StringBuffer与StringBuilder区别(转)及String类的一些基本操作代码
- FMDB的一些基本操作小结
- cookie的一些操作
- C#中对XML文件的一些基本操作
- Oracle 一些基本操作