1. 程式人生 > >Localhost 無法設定cookie問題

Localhost 無法設定cookie問題

Map<String, String> cookieMap = new HashMap<String, String>();
cookieMap.put(SSO_UID, principal);
cookieMap.put(NONCE, encodeBase64String(nonce));
cookieMap.put(CREATED, System.currentTimeMillis() + "");
StringBuilder cookie = new StringBuilder();
cookie.append(ARGUS_SSO_COOKIE);
cookie.append("=");
cookie.append(mapEncryptionService.encrypt(cookieMap));
cookie.append(";Path=/;HttpOnly;domain=localhost"); FacesContext.getCurrentInstance().getExternalContext().addResponseHeader("Set-Cookie", cookie.toString());

使用以上方式set cookie的時候,由於localhost不是有效的域名,在Chrome和IE下會造成設定不成功。ff是可以的。
去掉domain=localhost就可以了。