Spring Logout
 Spring Logout 
 303/302 return
1
2
3
4
5
6
7
8
9
10
11
12
@GetMapping("/login")
public String login2(HttpServletResponse resp) {
	String jwt = "123";
	Cookie cookie = new Cookie("JWT_TOKEN", jwt);
	cookie.setHttpOnly(true);
	cookie.setPath("/");
	resp.addCookie(cookie);
	return "forward:/index.html";
	// or 
	return "index.html";
}
1
2
3
4
5
6
7
8
9
10
@GetMapping("/login")
public ModelAndView login(HttpServletResponse resp) {
	String jwt = "123";
	Cookie cookie = new Cookie("JWT_TOKEN", jwt);
	cookie.setHttpOnly(true);
	cookie.setPath("/");
	resp.addCookie(cookie);
	return new ModelAndView("redirect:index.html");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@GetMapping("/login")
public ResponseEntity<Void> login(HttpServletRequest req, HttpServletResponse resp) {
	String jwt = "123";
	ResponseCookie cookie = ResponseCookie.from("JWT_TOKEN", jwt)
			.httpOnly(true)
			.secure(true)
			.sameSite("Lax")
			.path("/")
			.maxAge(60 * 60)
			.build();
	ResponseEntity<Void> build = ResponseEntity.status(HttpStatus.SEE_OTHER) // 303
			.header(HttpHeaders.SET_COOKIE, cookie.toString())
			.location(URI.create("index.html"))
			.build();
	return build;
}
Inside Server redirect
Note! If the
1
2
3
4
5
6
7
8
9
10
@GetMapping("/login")
public RedirectView redirectView(HttpServletResponse resp) {
	String jwt = "123";
	Cookie cookie = new Cookie("JWT_TOKEN", jwt);
	cookie.setHttpOnly(true);
	cookie.setPath("/");
	resp.addCookie(cookie);
	return new RedirectView("index.html");
}
 This post is licensed under  CC BY 4.0  by the author.