zoukankan      html  css  js  c++  java
  • cookie记住账户密码

     1 //cookie保存路径
     2 String autologin=request.getParameter("autologin");
     3 String path = request.getContextPath()+"/";                   
     4 if(autologin!=null&&autologin.equals("on")){                            
     5        Cookie cookie = new Cookie("user",username+"-"+password);
     6        cookie.setMaxAge(60 * 60 * 24 * 14);                                                       
     7        cookie.setPath(path);                    
     8        response.addCookie(cookie);
     9  }else{//清空cookie
    10        Cookie[] cookies = request.getCookies();                             
    11        for(int i=0;i<cookies.length;i++){
    12            if(cookies[i].getName().equals("user")){
    13                 //System.out.println(cookies[i].getName() + ":" + cookies[i].getValue());  
    14                 Cookie cookie = new Cookie(cookies[i].getName(), null);  
    15                 cookie.setMaxAge(0);  
    16                 cookie.setPath(path);//根据你创建cookie的路径进行填写      
    17                 response.addCookie(cookie);
    18             }                                   
    19       } 
    20  }   
     1 //页面取cookie
     2 <%
     3 String name=""; 
     4 String passward=""; 
     5 Cookie[] cookies=request.getCookies(); 
     6 if(cookies!=null){ 
     7     for(int i=0;i<cookies.length;i++){ 
     8         if(cookies[i].getName().equals("user")){  
     9             name=cookies[i].getValue().split("-")[0]; 
    10             passward=cookies[i].getValue().split("-")[1]; 
    11             request.setAttribute("username",name); 
    12             request.setAttribute("password",passward); 
    13         } 
    14     } 
    15 } 
    16 %>
  • 相关阅读:
    《人件》阅读笔记五
    《人件》阅读笔记四
    《人件》阅读笔记三
    《人件》阅读笔记二
    《人件》阅读笔记一
    年报系统课堂讨论记录
    系统利益相关者描述案例
    Android开发学习记录--活动生命周期
    jQuery AJAX简介
    jQuery HTML简介
  • 原文地址:https://www.cnblogs.com/-lpf/p/5710537.html
Copyright © 2011-2022 走看看