zoukankan      html  css  js  c++  java
  • cookie的删除

    package day01.cookies;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class CookieDemo02 extends HttpServlet {
    
    	private static final long serialVersionUID = 2691008160310371013L;
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		request.setCharacterEncoding("utf-8");
    		response.setContentType("text/html;charset=utf-8");
    		// 当有效时间为0的时候,就是删除同名的cookie,提交一个同名的cookie进行覆盖
    		// 并且因为有效时间为0,所以覆盖了之后,就消失了,达到了消除的效果
    		Cookie c = new Cookie("stu_name", "abc");
    		c.setMaxAge(0);
    		
    		response.addCookie(c);
    		System.out.println("删除成功!");
    	}
    
    	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		request.setCharacterEncoding("utf-8");
    		response.setContentType("text/html;charset=utf-8");
    		
    	}
    
    }
    

  • 相关阅读:
    【BZOJ 5000 OI树】
    九、表锁
    八、ORDER BY优化
    七、索引优化分析
    六、JVM之垃圾回收
    五、JVM之堆内存
    四、JVM之栈与栈帧
    三、JVM之方法区
    二、JVM之体系结构
    一、JVM之类加载器
  • 原文地址:https://www.cnblogs.com/mzywucai/p/11053513.html
Copyright © 2011-2022 走看看