Spring Boot Cookie

It’s not special

To handle cookie, there are no special way for Spring Boot. It’s same as general Servlet

Get HttpServletRequest, HttpServletResponse

@RequestMapping(value="/testcookie", method = RequestMethod.GET)
	public String testCookie(HttpServletRequest request, 
HttpServletResponse response) {
}

We can use request, response with arguments.

Add Cookie

Cookie cookie = new Cookie("test", "Boon");
cookie.setMaxAge(265 * 24 * 60 * 60);  // (s)
cookie.setPath("/");
response.addCookie(cookie);   // response: HttpServletResponse

Delete Cookie

Set Max age 0 with same parameters
It means override same key and value

Cookie cookie = new Cookie("test", null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);   // response: HttpServletResponse