I am new to the spark framework. I got problem when i was trying to set cookie to response or read cookie from request.
The route:
post("/test/set/cookie", TestController.setCookie);
get("/test/get/cookie", TestController.getCookie);
post("/test/remove/cookie", TestController.removeCookie);
controller:
public static Route setCookie = (Request request, Response response) -> {
System.out.println("set");
String id = UUID.randomUUID().toString();
response.cookie("test1", id, 3600, false, true);
return "done";
};
public static Route getCookie = (Request request, Response response) -> {
System.out.println("get");
String cookie = request.cookie("test1");
System.out.println(cookie);
return "done";
};
public static Route removeCookie = (Request request, Response response) -> {
System.out.println("remove");
response.removeCookie("test1");
return "done";
};
what i am missing?
I solved it finally---
response.cookie("/", "test", "value", 3600, false, true);
just need to add the path
"/"
to the cookie.