클라이언트와 웹서버간의 연결을 지속적으로 유지해주게 하는 것
근데 세션도 그렇지 않아? 세션 vs 쿠키
장점
단점
- 그래서 인정보를 쿠키에 저장하면 안됨
https://soulno.tistory.com/39
response가 계속 나오는 이유 (response.addCookie 등)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cookie01</title>
</head>
<body>
<%
Cookie cookie_id = new Cookie("userid", "admin"); // (name, value)
response.addCookie(cookie_id);
Cookie cookie_psw = new Cookie("userpsw", "admin1234");
response.addCookie(cookie_psw);
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cookie02</title>
</head>
<body>
<%
Cookie [] cookies = request.getCookies() ;
if(cookies == null){
out.print("쿠키 값이 없습니다");
return;
}
for(Cookie co : cookies){
out.print("<br>" + co.getName() + " : " + co.getValue() + "<br>");
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cookie3</title>
</head>
<body>
<%
for(Cookie co : request.getCookies()){
if(co.getName().equals("userpsw")){ // co.getName().trim()까지 해도 그만 안해도 그만
co.setMaxAge(0);
response.addCookie(co);
}
};
%>
</body>
</html>