gpt4 book ai didi

java - 如何用Spring将 'Cookie'头解析为 `javax.servlet.http.Cookie`?

转载 作者:行者123 更新时间:2023-11-30 03:31:41 24 4
gpt4 key购买 nike

我想将 http 请求中 cookie header 的值解析为 javax.servlet.http.Cookie 实例。

示例,请求中的 Cookie:

Cookie: HSID=AYQEVnDKrdst; Domain=.foo.com; Path=/aaa; HttpOnly

spring是否提供了一些实用工具来轻松解析它?我不想手动解析它或涉及一些其他库

最佳答案

Spring提供@CookieValue作为处理程序方法参数的注释。它支持Cookie作为参数类型以及Stringint

Annotation which indicates that a method parameter should be bound to an HTTP cookie. Supported for annotated handler methods in Servlet and Portlet environments.

The method parameter may be declared as type javax.servlet.http.Cookie or as cookie value type (String, int, etc).

在幕后,它使用 WebUtils#getCookie将值解析为 Cookie

关于java - 如何用Spring将 'Cookie'头解析为 `javax.servlet.http.Cookie`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com