首页 > 代码库 > java会话管理之Cookie基础(写着玩)

java会话管理之Cookie基础(写着玩)

1. Cookie 存储在客户端

2. 创建cookie

  

Cookie c = new Cookie("name",  "value");

 

3. 添加cookie

  

response.addCookie(c);

 

4. 接收cookie

  

Cookies[] cookies = request.getCookies();

 

5. for循环遍历

if (cookies != null) {  for (Cookie cookie : cookies) {    String name = cookie.getName();    String value = cookie.getValue();    System.out.println(name + "=" + value);}

 

java会话管理之Cookie基础(写着玩)