BlogJava 联系 聚合 管理  

Blog Stats

随笔档案

文章档案

Infernu的Google site


Infernus-JXH

testcookie.jsp (cookie的写入)

<%
 String username = request.getParameter("username");//使用getParameter得到用户输入的username传字符串username
 String password = request.getParameter("password");
 
 Cookie c1 = new Cookie("username", username);//将字符串username传给c1
 Cookie c2 = new Cookie("password", password);
 c1.setMaxAge(14 * 24 * 60 * 60);//设在cookie的最大时间为14天*24小时*60分*60秒
 c2.setMaxAge(14 * 24 * 60 * 60);
 response.addCookie(c1);//将cookie写入用户机
 response.addCookie(c2);
%>

login.jsp(cookie的读取)

<%
 Cookie[] cs = request.getCookies();//那出所有cookie付给数组cs
 String username = "";
 String password = "";
 for(Cookie c : cs) {//循环用c替代cs中的每一个元素
  if(c.getName().equals("username")) {//如果c里的名字和username相同
   username = c.getValue();//将c的值传给username
  }
  else if(c.getName().equals("password")) {
   password = c.getValue();
  }
 }
%>
posted on 2009-09-30 10:54 Infernus 阅读(109) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: