JSP---设置CooKIe

增加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>

 

转载于:https://www.cnblogs.com/anuo007/p/3583395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值