处理cookies

路由添加cookie处理程序。

router.route().handler(CookieHandler.create());

操作cookie

使用getCookie获取cookie.

删除用removeCookie.

添加addCookie.

添加cookie后会自动写回响应中。

例如

router.route().handler(CookieHandler.create());

router.route("some/path/").handler(routingContext -> {

  Cookie someCookie = routingContext.getCookie("mycookie");
  String cookieValue = someCookie.getValue();

  // Do something with cookie...

  // Add a cookie - this will get written back in the response automatically
  routingContext.addCookie(Cookie.cookie("othercookie", "somevalue"));
});

猜你喜欢

转载自blog.csdn.net/zyydecsdn/article/details/80279371