<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## Web專題二:Cookie與Session [TOC] ### 1.1. Cookie [http://www.rfc-editor.org/rfc/rfc6265.txt](http://www.rfc-editor.org/rfc/rfc6265.txt) > HTTP是一種無狀態協議,Cookie的出現正好解決了這種問題,Cookie是一種用來保存狀態的機制,描述了從服務器發送狀態信息給user agent(一般是瀏覽器)和從user agent返回狀態信息給服務器的過程 User-Agent: ~~~ Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36 ~~~ #### 1.1.1. Cookie過程 服務器在HTTP響應`response`時攜帶` Set-Cookie`頭部,返回給user agent,并保存在user agent中,在后面的HTTP請求`request`頭部可以攜帶Cookie頭部,Cookie的信息來自于前面user agent收到的` Set-Cookie` 例如:我們想發送一個` "session identifier"`給user agent ~~~ == Server -> User Agent == Set-Cookie: SID=31d4d96e407aad42 == User Agent -> Server == Cookie: SID=31d4d96e407aad42 ~~~ 當然也可以攜帶多個Cookie ~~~ == Server -> User Agent == Set-Cookie: SID=31d4d96e407aad42; Path=/; Secure; HttpOnly Set-Cookie: lang=en-US; Path=/; Domain=example.com == User Agent -> Server == Cookie: SID=31d4d96e407aad42; lang=en-US ~~~ #### 1.1.2. Cookie語法 每個Cookie都是以name-value對的方式開頭,中間以`; `分隔,后面跟著零個或多個的attribute-value對 - response ~~~ Set-Cookie: cookie-name=cookie-value; attribute=value Set-Cookie: cookie-name-1=cookie-value-1; attribute-1=value-1 ... Set-Cookie: cookie-name-n=cookie-value-n; attribute-n=value-n ~~~ - request ~~~ Set-Cookie: cookie-name=cookie-value; [cookie-name-1=cookie-value-1; ... cookie-name-n=cookie-value-n] ~~~ #### 1.1.3. Cookie屬性 | 屬性 | 說明 | 例子 | | --- | --- | --- | | Expires | 用日期、時間表示cookie生存最大的生命周期 |Expires=Sun, 06 Nov 1994 08:49:37 GMT | | Max-Age | 用秒數表示cookie生存最大的生命周期,比Expires的優先級更高 |Max-Age=65535 | | Domain | 表示cookie可以被發送到哪些主機 |Domain=example.com| | Path | 表示cookie的作用域,沒有指定時缺省值是request-uri的路徑|Path=/| | Secure | 表示cookie使用安全頻道如TSL發送|Secure| | HttpOnly | 限定cookie只用于HTTP請求,不用于非HTTP的API,如把web瀏覽器中cookie暴露出來的腳本|HttpOnly| ` javax.servlet.http.Cookie`就包含了這些屬性 ~~~ // javax.servlet.http.Cookie public class Cookie implements Cloneable, Serializable { private static final long serialVersionUID = 1L; private final String name; private String value; private int version = 0; private String comment; private String domain; private int maxAge = -1; private String path; private boolean secure; private boolean httpOnly; } ~~~ ### 2.1. session > Session保存在服務端的一種數據,用來跟蹤用戶的會話狀態,默認保存在服務器的一個文件中 實現方式主要有下面幾種: - Cookie實現: 將session-id保存在Cookie中,如:`Set-Cookie: SID=31d4d96e407aad42`,在第一次請求服務器將session-id放入Cookie中返回給user agent,后續user agent發送請求服務器就能從session-id中知道是哪個用戶在操作 - URL重寫: 將session-id作為參數添加在url的后面 - 表單隱藏: 提交表單時,將session-id作為一個隱藏字段,發送給服務器
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看