如何在JSP中正确设置子域的cookies?
我有以下设置:如何在JSP中正确设置子域的cookies?,jsp,servlets,cookies,Jsp,Servlets,Cookies,我有以下设置: 所有请求都是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.l
- 所有请求都是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
然后在app atloc
中,我有一个按钮,在另一个app atloc2
中发送用户,将用户重定向到loc3loc3。localdomain:8092/coolApp/bro/something/more
。因此,此时我应该在loc3
处的应用程序请求中看到cookie,但我没有看到
Cookies设置:
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);
知道这个设置有什么问题吗?基于此()域应该至少包含2个点,因此答案是使用localhost的其他别名来模拟我的子域。类似于:*.example.com
更改域后,所有操作都按预期进行