gpt4 book ai didi

jsp - 如何正确设置JSP中子域的cookie?

转载 作者:行者123 更新时间:2023-12-03 09:00:26 25 4
gpt4 key购买 nike

我有以下设置:

  • 所有请求都是https(我将在下面的描述中省略这一点)
  • 3 个 Docker 服务器:localhost:8090、localhost:8091、localhost:8092
  • 在主机(在我的 Windows 计算机上)中,我有 3 个域:loc.localdomain、loc2.localdomain 和 loc3.localdomain 均指向我的 IP 地址
  • 所以我将在我的应用程序中使用 localhost:8090 -> loc.localdomain、localhost:8091 -> loc2.localdomain 和 localhost:8092 -> loc3.localdomain

现在我在 loc 上有一个应用程序,它为 loc3 子域设置一些 cookie。我看到 cookie 在 chrome 网络响应中设置(或假设设置)。

Set-Cookie: MY_COOKIE=YUMM; domain=loc3.localdomain; 
expires=Fri, 21-Jun-2019 10:48:58 GMT; path=/coolApp/bro

然后在 loc 的应用程序中,我有一个按钮,可以将用户发送到 loc2 的另一个应用程序中,将用户重定向到 loc3 loc3.localdomain:8092/coolApp/bro/something/more。因此,此时我应该在 loc3 的应用请求中看到 cookie,但我没有。

Cookie 设置:

FacesContext facesContext = FacesContext.getCurrentInstance();
//facesContext.getExternalContext().addResponseCookie("TEST", "TEST", properties); tried this too
//then in properties will be the maxAge, path and domain set

Cookie cookie = (Cookie) facesContext.getExternalContext().getRequestCookieMap().get("MY_COOKIE");
if(cookie == null){
cookie = new Cookie("MY_COOKIE", "YUMMM");
}

cookie.setMaxAge(31536000);
cookie.setPath("/coolApp/bro");
cookie.setDomain("loc3.localdomain"); // I've tried ".localdomain" too

HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addCookie(cookie);

知道这个设置有什么问题吗?

最佳答案

基于此( https://curl.haxx.se/rfc/cookie_spec.html ),域应包含至少 2 个点,因此答案是使用 localhost 的其他别名来模拟我的子域。类似于:*.example.com

更改域名后,一切都按预期进行。

关于jsp - 如何正确设置JSP中子域的cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50966861/

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