【问题标题】:Spring MVC ResponseEntity and CookiesSpring MVC ResponseEntity 和 Cookie
【发布时间】:2017-04-15 19:15:33
【问题描述】:

我正在尝试将Cookies 添加到ResponseEntity,但我不确定Adding cookies to header 是否是最佳做法。

1.当使用cookies时,我应该使用HttpServletResponse这样的不同响应吗?

2.在这种情况下如何添加属性(setMaxAge, setSecure)?

谢谢。

【问题讨论】:

    标签: spring-mvc cookies


    【解决方案1】:

    我会在 httpresponse 中添加 cookie。在here 有很好的教程

    【讨论】:

    • 我询问了 ResponseEntity,我不想使用 HttpServletResponse 重新构建响应。
    • 我没试过。但也许使用: HttpHeaders headers = new HttpHeaders(); headers.add("Set-Cookie","cookie-name=cookievalue;max-age=*;expires=date; ..."); 然后在 EntityResponse 中设置它可能是个好主意.
    猜你喜欢
    • 2020-05-23
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2018-01-23
    • 2013-12-18
    • 1970-01-01
    • 2018-12-25
    • 2012-04-18
    相关资源
    最近更新 更多