[TOC]

## 問題01:cookie是什么?
cookie是小段的文本信息,可以標識用戶身份,記錄用戶名和密碼,跟蹤重復用戶等。
cookie是在網絡**服務器上生成**,并發送給瀏覽器的。并以**key/value**的形式保存到**客戶機**的某個指定目錄中。
## 問題02:cookie的增刪改查?
### 1. cookie的寫入
```
Cookie cookie = new Cookie("name","value");
response.addCookie(cookie);
```
> **cookie不能保存中文**
> **void javax.servlet.http.HttpServletResponse.addCookie(Cookie cookie)**
> Adds the specified cookie to the response. This method can be called multiple times to set more than
one cookie.
### 2. 設置cookie的存活時間
```cookie.setMaxAg(int seconds) ```
> void javax.servlet.http.Cookie.setMaxAge(int expiry)
> **Parameters**: expiry an integer specifying the maximum age of the cookie **in seconds**; if **negative**, meansthe cookie is **not stored**; if **zero**, **deletes** the cookie.
### 3. 獲取cookie數組
```request.getCookies();```
* [ ] 獲取指定cookie的name
```cookie.getName() ```
* [ ] 獲取指定cookie的value
```cookie.getValue() ```
### 4. EL讀取cookie
```
${cookie.XXX.value}
```
## 問題03:保存中文Cookie
```
URLEncoder.encode(value,"UTF-8"))
```
> **如果需要使用EL表達式讀取中文cookie,則可以使用自定義標簽庫,編寫解碼函數**
```
${custom:decoder(cookie.XXX.value,'UTF-8') }
```
- 1課程概述
- 2環境配置
- 3MVC
- 3.1View
- 3.1.1前端基礎
- 3.1.2JSP語法
- 3.1.3JSP內置對象1
- 3.1.4JSP內置對象2
- 3.2Bean
- 3.3Controller
- 3.3.1Servlet
- 3.3.2Filter
- 3.3.3Listener
- 3.4EL&JSTL
- 4三層架構
- 4.1數據庫操作
- 4.1.1JDBC
- 4.1.2JDBC優化
- 4.2三層架構設計
- 4.3程序優化
- 4.3.1數據庫連接優化
- 4.3.2數據庫操作優化
- 4.4安全專題
- 4.4.1Ajax異步查詢
- 4.4.2CAPTCHA
- 4.4.3MD5&SHA
- 4.4.4Cookie
- 4.4.5分頁顯示
- 4.4.6文件上傳
- 4.4.7發送郵件
- 5企業級框架
- 5.0Maven
- 5.1MyBatis
- 5.2Spring
- 5.3SpringMVC
- 6實踐項目
- 6.1實驗1-用戶登錄(MVC)
- 6.2實驗2-訪問統計(Servlet高級)
- 6.3實驗3-三層架構
- 6.4實驗4-安全信息系統