java后端设置Cookie和响应Cookie
@Slf4j
@RestController
@CrossOrigin
public class LoginController {
@GetMapping("/c1")
public Result cookie1(HttpServletResponse response){
response.addCookie(new Cookie("Login_user","zwj"));
return new Result().success();
}
@GetMapping("/c2")
public Result cookie2(HttpServletRequest request){
Cookie[] cookies=request.getCookies();
for(Cookie cookie:cookies){
if(cookie.getName().equals("Login_user")){
System.out.println("Login_user: "+cookie.getValue());
}
}
return new Result().success();
}
}