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 %>
  • 相关阅读:
    磁盘相关命令
    shell $用法
    setuid setgid stick bit 特殊权限 粘滞位
    运维面试题2
    mysql 外键约束
    创建MySQL 用户
    shell 脚本定时创建月份表
    apache 配置多个虚拟主机,不同的端口
    sublime3中文乱码解决包ConvertToUTF8.zip
    yii2安装
  • 原文地址:https://www.cnblogs.com/-lpf/p/5710537.html
Copyright © 2011-2022 走看看