标签:
1.什么是cookie?
保存到客户端的一个文本文件,与特定客户相关 javax.servlet.http.Cookie;
2.写cookie
import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class A1Cookie extends HttpServlet { protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,java.io.IOException { Cookie c1=new Cookie("username","zhangsan"); resp.addCookie(c1); Cookie c2=new Cookie("password","123"); c2.setMaxAge(3600); resp.addCookie(c2); resp.setContentType("text/html"); resp.getWriter().println("成功"); } }
2.cookie分为两种,长期还是临时--硬盘,内存(浏览器会话结束时)
3读cookie
标签:
原文地址:http://www.cnblogs.com/yuanbao1991/p/5226908.html