我有一个运行的现有Web应用程序
https://subdomain.example.com
现在,我想拥有其他子域
https://subdomain2.example.com
如何使用Spring MVC设置以下内容,以便在从第一个域重定向到第二个域后,不会再次提示用户进行身份验证?
Set-Cookie: name=value; domain=example.com
查看此控制器示例,但请记住两点:
班级:
package com.test.foo;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/foo")
public class FooController {
@RequestMapping("/cookie")
public String setCookie(HttpServletRequest request, HttpServletResponse response) {
String value = "value";
Cookie cookie = new Cookie("name", value);
cookie.setPath("/");//<-- important
cookie.setDomain("example.com");
response.addCookie(cookie);
return "foo/index";//your view
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句