cookie
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cookie相关的知识,希望对你有一定的参考价值。
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
以上是关于cookie的主要内容,如果未能解决你的问题,请参考以下文章