簡體   English   中英

更新JSESSIONID Cookie值

[英]Updating JSESSIONID cookie value

我正在嘗試如下更新JSESSIONID值,但它會為每個請求創建一個新的JSESSIONID cookie。

    Cookie[] cookies = httpRequest.getCookies();
    Cookie jsessionCookie = null;
    Cookie hazelcastCookie = null;
    if (cookies != null) for (Cookie cookie : cookies) {
        if (cookie.getName().equals(JSESSION_COOKIE_NAME))
            jsessionCookie = cookie;
        else if (cookie.getName().equals(HAZELCAST_COOKIE_NAME)) hazelcastCookie = cookie;
    }
    if (jsessionCookie != null && hazelcastCookie != null
            && jsessionCookie.getValue() != hazelcastCookie.getValue()) {
        jsessionCookie.setValue(hazelcastCookie.getValue());
        httpResponse.addCookie(jsessionCookie);
        LOGGER.log(Level.DEBUG,
                "Updated jsessionCookie value with  hazelcastCookie --> " + jsessionCookie.getValue());
    }

我應該做些什么更改以僅更新JSESSIONID值,而不是為每個請求創建一個新值?

更新

請求標題

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:WebDAV.activeX=false; JSESSIONID=HZ9542C5A55A7142A28935DFF96746230F; hazelcast.sessionId=HZ9542C5A55A7142A28935DFF96746230F; JSESSIONID=HZ9542C5A55A7142A28935DFF96746230F; sessionIdForCognos=HZ9542C5A55A7142A28935DFF96746230F; _sd3_session_id=5436c0eebe806f38ca8d1e2867338e00

響應標題

Cache-Control:no-cache
Connection:Keep-Alive
Content-Encoding:gzip
Content-Language:en-US
Content-Length:6538
Content-Type:text/html;charset=utf-8
Date:Thu, 14 Apr 2016 22:20:36 GMT
Expires:Wed, 31 Dec 1969 23:59:59 GMT
Keep-Alive:timeout=70, max=57
Pragma:no-cache
Server:None
Set-Cookie:JSESSIONID=508E10266957BFF95874CEBFECF5FBAF.qa-trunk-n2; Path=/Passport; Secure; HttpOnly
Set-Cookie:hazelcast.sessionId=HZ9542C5A55A7142A28935DFF96746230F; Path=/Passport
Set-Cookie:JSESSIONID=HZ9542C5A55A7142A28935DFF96746230F

如果要設置現有cookie的值,則cookie的以下字段必須全部相同:

  1. 路徑
  2. 安全
  3. 僅http
  4. 名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM