博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java_Cookie_example(你上次访问的时间)
阅读量:7285 次
发布时间:2019-06-30

本文共 852 字,大约阅读时间需要 2 分钟。

 

public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		response.setCharacterEncoding("UTF-8");		response.setContentType("text/html;charset=UTF-8");		PrintWriter out = 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.currentTimeMillis()+"");		cookie.setMaxAge(1*30*24*3600);		cookie.setPath("/Test");				response.addCookie(cookie);			}

转载于:https://www.cnblogs.com/MarchThree/p/3720433.html

你可能感兴趣的文章
android.widget.Spinner
查看>>
LAMP下tomcat使用命令
查看>>
ipvsadm 命令积累
查看>>
go的time
查看>>
SQL语句大全
查看>>
路由器怎么设置映射?
查看>>
LayoutAnimation的使用
查看>>
苹果电脑Mac很久不用,accountsd Messages 登陆钥匙串一直提示输入密码 错误
查看>>
jquery获得select option的值 和对select option的操作
查看>>
XSuperNEST——成本小管家
查看>>
Android之Bundle传递数据详解与实例及Bundle与SharedPreferences的区别
查看>>
struts1、 struts2所有版本jar包下载地址大全
查看>>
如何电脑上怎样查看微信聊天记录
查看>>
Thrift 基础架构
查看>>
many-to-many
查看>>
java中的多态
查看>>
Python 函数式编程--装饰器
查看>>
11月28号
查看>>
DAS、NAS、SAN、iSCSI 存储方案概述
查看>>
为VMware esxi主机配置系统日志记录
查看>>