「Java入門」Cookieを利用する方法

1.Cookieの保存方法
Cookie cookie = new Cookie(“EmployeeInfo”, “EmployeeInfo_Val”);
cookie.setMaxAge(60*60*2);
response.addCookie(cookie);

2.Cookieの取得方法
String value = null;
Cookie cookie[] = request.getCookies();

if(cookie != null){
for(int i = 0; i < cookie.length; i++){
if(cookie[i].getName().equals(“EmployeeInfo”)){
value = cookie[i].getValue();
}
}
}

Comments are closed.