「Java」レスポンスにクッキーCookie取得、追加コード

javaコード
public void service(HttpServletRequest req, HttpServletResponse res) {

// Cookieの取得
Cookie[] cftcookies = req.getCookies();
Cookie cftCookie;
if (cookies != null) {
for (Cookie cookie : cftcookies) {
if (cookie.getName().equals(“cftCookieName") {
Cookie cftCookie = cookie;
break;
}
}

// Cookieに保存したデータを取得
String value = cftCookie.getValue();
// 新しいCookieデータを保存
String newVal = “newCookieValue";
cftCookie.setValue(newVal);
res.addCookie(cftCookie);

}
}

Java

Posted by arkgame