• Cookie 获取访问时间


    服务器将客户端需要缓存的数据,发送到客户端,客户端保存在本地的这些缓存数据就是Cookie。区别于Session。

     

    获取用户访问时间代码:

    response.setCharacterEncoding(“UTF-8”);

    response.setContentType(“text/html;charset=UTF-8”);

     

    PrintWrite oout = response.getWriter();

    out.print(“您上次访问的时间是:”);

     

    //获取用户的时间Cookie

    Cookie cookies[] = request.getCookies();

    for(int i = 0; cookies!=null && i < cookies.length;i++){

    if(cookies[i].getName().equals(“lastAccessTime”)){

           long cookieValue = Long.parseLong(cookies[i].getValue());

           Date date = new Date(cookieValue);

          

           out.print(date.toLocaleString());

    }

    }

    //将最新访问时间会送用户

    Cookie cookie = new Cookie(“lastAccessTime”,System.currentTimeMills()+””);

    cookie.setPath(“/web”);

    cookie.setMaxAge(30*24*3600);

    response.addCookie(cookie);

  • 相关阅读:
    反向代理实例
    nginx常用命令和配置
    nginx的安装
    Can Live View boot up images acquired from 64bit OS evidence?
    What is the behavior of lnk files?
    EnCase v7 search hits in compound files?
    How to search compound files
    iOS 8.3 JB ready
    Sunglasses
    现代福尔摩斯
  • 原文地址:https://www.cnblogs.com/flying607/p/3452248.html
Copyright © 2020-2023  润新知