javaWeb 使用cookie显示上次访问网站时间
package de.bvb.cookie; import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date; import javax.enterprise.inject.ResolutionException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.DateFormatter; /**
* 显示上次访问时间
*
* @author joker
*
*/
public class CookieDemo1 extends HttpServlet { 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.write("您上次访问的时间是: "); // 获取上次访问时间
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());
out.write(new Date(cookieValue).toLocaleString());
}
} // 保存本次访问时间
Cookie cookie = new Cookie("lastAccessTime", System.currentTimeMillis()
+ "");
response.addCookie(cookie); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet(request, response);
} }
javaWeb 使用cookie显示上次访问网站时间的更多相关文章
- cookie案例-显示用户上次访问网站的时间
package cn.itcast.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.D ...
- 02-cookie案例-显示用户上次访问网站的时间
package cookie; import java.io.IOException;import java.io.PrintWriter;import java.util.Date; import ...
- 使用Coookie实现浏览器显示上次的登录时间
实现的效果: 每一次刷新 都会显示上一次访问servlet的时间 ,只适用于同一个浏览器 ,更换浏览器再次访问就该使用session技术了, 因为cookie是浏览器端技术,cookie保存在浏览器 ...
- java_Cookie_example(你上次访问的时间)
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...
- cookie ? 利用cookie实现 显示上次访问时间?
二. <%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.D ...
- javaWeb 使用cookie显示商品浏览记录
package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...
- cookie 保存上次访问url方法
if (Session[Enums.UserInfoSeesion] == null) { HttpCookie cookie = Request.Cookies[Enums.UserLastAcce ...
- 黄聪:wordpress如何携带cookie模拟浏览器访问网站
$args = array( 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, li ...
- JavaWeb 8 Cookie
JavaWeb 8 Cookie 2. 会话管理入门 2.1 生活中会话 我: 小张,你会跳小苹果码? 小张: 会,怎么了? ...
随机推荐
- 使用sed,awk将love转换成LOVE,将CHINA转换成china
将love转换成LOVE,将CHINA转换成china echo "love CHINA" | sed -e 's/love/LOVE/' -e 's/CHINA/china/' ...
- 与(and)&&
/与(and)&& var box = (5>3)&&(4>3); alert(box); //true 如果脸变的操作数有一个操作数不是boolean值得 ...
- Java对日期Date类进行加减运算,年份加减,月份加减
import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; public class Da ...
- Linux系统 ssh图形界面远程
远程Linux系统有图形界面 1.下载xming 并安装启动 2.通过putty登陆虚拟机 3.输入gnome-session
- CAM350测量
CAM350 测量方法 1. 单位设置:在菜单:Settings 下选中 Unit: 英制 公制 精确度 CAM350 软件默认的是英制,不习惯用英制的人,就改为公制的呀 软件默认的是英制 就改为公制 ...
- sqlserver 2000事务复制问题
2000现在用的估计不多了,把之前收集的一些复制问题整理发布出来.可能都是些很白很二的问题,但人总是由最初的无知不断成长,不对之处欢迎指正. sqlserver 2000事务复制问题服务器A(发布) ...
- Vue.2.0.5-过渡效果
概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.c ...
- 解决:打开OleView报错 dllregisterserver in iviewers failed
用管理员权限运行OleView.exe即可(Visual Studio Tools\VS20XX开发人员命令提示 -> 用管理员权限运行 -> 输入OleView) http://stac ...
- 转:VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径
http://www.cnblogs.com/lidabo/archive/2012/05/29/2524170.html
- ios理解 -- Pro Mutlithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch, and Blocks
Capturing automatic variables Next, you need to learn what the “together with automatic (local) vari ...