controller重定向页面并向页面写入cookie,但是目标页面无法获取cookie
cookie只能被当前目录和子目录访问
使用setPath方法设置path为”/“,这是server的根目录,多看看api问题就能解决。
public void setPath(String uri)
Specifies a path for the cookie to which the client should return the cookie.
The cookie is visible to all the pages in the directory you specify, and all the pages in that directory’s subdirectories. A cookie’s path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.
Parameters:
uri - a String specifying a path
See Also:
getPath()