zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    EasyUI
    intellij idea打包maven项目
    struts2框架详解
    java电子书
    查看mysql安装路径
    springboot 集成 vue
    C#中的属性
    C#中的时间戳
    int.TryParse非预期执行引发的思考
    IQueryable 和 IEnumerable 的区别
  • 原文地址:https://www.cnblogs.com/flying607/p/3452248.html
Copyright © 2011-2022 走看看