◇ PART · BOARD

쿠키 깊이 보기

Spring 기초
SMHRD

학습 목표

1. 문제

쿠키가 어디 있는지 본 적이 없다.

2. 새 도구

F12 → Application → Cookies: 브라우저 안에 저장되어 매 요청에 자동으로 함께 보내짐.

3. 코드

// 서버에서 쿠키 발급 @GetMapping("/setcookie") public String setCookie(HttpServletResponse resp) { Cookie c = new Cookie("favorite", "blue"); c.setMaxAge(60 * 60 * 24); // 24 시간 c.setPath("/"); resp.addCookie(c); return "redirect:/"; } // 서버에서 쿠키 읽기 @GetMapping("/getcookie") public String getCookie(@CookieValue(value="favorite", required=false) String fav) { System.out.println("선호 색상: " + fav); return "home"; }

4. 정리

5. Before / After

전 차시

쿠키가 어디 있는지 본 적이 없다.

이번 차시

쿠키 발급·읽기·만료 옵션을 안다.

학습 확인 체크리스트