狮子的鱼 2016-04-04 13:02 采纳率: 0%
浏览 2775
已结题

我设置了Session的setmaxage为0但是依然无法删除cookie

这是设置session的代码

<%
    //为first_name和last_name设置cookie
    Cookie firstName = new Cookie("frist_name",request.getParameter("frist_name"));
    Cookie lastName = new Cookie("last_name",request.getParameter("last_name"));

    //设置cookie过期时间为1分钟
    firstName.setMaxAge(60*60*24);
    lastName.setMaxAge(60*60*24);

    //在响应头部添加cookie
    response.addCookie(firstName);
    response.addCookie(lastName);
%> 

#这是删除Cookie的代码

<%
        Cookie cookie = null;
        Cookie[] cookies = null;
        //获取当前Cookies

        cookies = request.getCookies();

        for(int i = 0;i < cookies.length;i++){
            cookie = cookies[i];
            if((cookie.getName()).compareTo("frist_name") == 0){
                cookie.setMaxAge(0);
                cookie.setPath("/");
                response.addCookie(cookie);
                out.print("已删除" + cookie.getName());
            }else{
    %>
                <h1>No found Cookie</h1>            
    <%
            }
        }
    %>

他们不在同一个jsp文件里

  • 写回答

1条回答

  • devmiao 2016-04-04 15:41
    关注
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?