我在 Servlet 中设置 Cookie,如下所示
Cookie NameCookie = new Cookie("Name", "Mugil Vannan");
NameCookie.setMaxAge(30*60);
response.addCookie(NameCookie);
Cookie LocationCookie = new Cookie("Location", "India");
LocationCookie.setMaxAge(30*60);
response.addCookie(LocationCookie);
设置 cookie 后,我正在尝试访问名称下的特定 cookie 集
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++)
{
Cookie cookie = cookies[i].getName().equals("Name");
String cookieName = cookie.getName();
String cookieValue = cookie.getValue();
out.print(cookieValue);
}
现在它显示为TypeMismatch:Cannot Convert Boolean to Cookie at
cookies[i].getName().equals("姓名");
知道为什么会这样