增加CooKie
1 <%@ page contentType="text/html" pageEncoding="GBK"%> 2 <html> 3 <head><title>page属性</title></head> 4 <body> 5 <% 6 Cookie c1=new Cookie("anuo008","46454");//定义新Cookie 7 Cookie c2=new Cookie("anuo005","464ff"); 8 c1.setMaxAge(60);//设置保存时间 9 c2.setMaxAge(60); 10 response.addCookie(c1); //向客户端增加Cookie 11 response.addCookie(c2); 12 13 14 %> 15 16 </body> 17 </html>
取得CooKie
1 <%@ page contentType="text/html" pageEncoding="GBK"%> 2 3 <html> 4 <head><title>page属性</title></head> 5 <body> 6 <% 7 Cookie c[]=request.getCookies(); //取得全部Cookie 8 for(int x=0;x<c.length;x++){ //循环输出 9 10 %> 11 <h2>账号:<%=c[x].getName()%> 密码:<%=c[x].getValue()%></h3> 12 <% 13 } 14 %> 15 </body> 16 </html>