# servlet学习笔记（三）

2012/04/04 10:13

Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management.

A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Some Web browsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of your servlets.

Cookie myCookie=new Cookie("cookieNamne","cookieValue");

myCookie.setMaxAge(1000);

res.addCookie(myCookie);

Cookie[] allCookies = req.getCookies();

for (int i = 0;i < allCookies.length; i++){
}
}

0
3 收藏

0 评论
3 收藏
0