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显示上次访问网站时间的更多相关文章

  1. cookie案例-显示用户上次访问网站的时间

    package cn.itcast.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.D ...

  2. 02-cookie案例-显示用户上次访问网站的时间

    package cookie; import java.io.IOException;import java.io.PrintWriter;import java.util.Date; import ...

  3. 使用Coookie实现浏览器显示上次的登录时间

    实现的效果:  每一次刷新 都会显示上一次访问servlet的时间 ,只适用于同一个浏览器 ,更换浏览器再次访问就该使用session技术了, 因为cookie是浏览器端技术,cookie保存在浏览器 ...

  4. java_Cookie_example(你上次访问的时间)

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...

  5. cookie ? 利用cookie实现 显示上次访问时间?

    二. <%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.D ...

  6. javaWeb 使用cookie显示商品浏览记录

    package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...

  7. cookie 保存上次访问url方法

    if (Session[Enums.UserInfoSeesion] == null) { HttpCookie cookie = Request.Cookies[Enums.UserLastAcce ...

  8. 黄聪:wordpress如何携带cookie模拟浏览器访问网站

    $args = array( 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, li ...

  9. JavaWeb 8 Cookie

    JavaWeb 8 Cookie 2. 会话管理入门            2.1 生活中会话            我: 小张,你会跳小苹果码?            小张: 会,怎么了?      ...

随机推荐

  1. linux mknod命令解析

    linux mknod命令解析 http://www.cnblogs.com/cobbliu/archive/2011/07/05/2389014.html mknod:make node  生成设备 ...

  2. 安装nodejs+ionic+cordova环境心得

    1.安装node-v0.10.38-x64.msi版本(从nodejs中下载最稳定版本,最后安装ionic安不上,然后又安装node-v0.10.38-x64.msi,再安装ionicok了.不知道是 ...

  3. Ubuntu下virtualbox nat网络模式下 实现宿主机访问虚拟机

    参考原文(在windows环境下):http://hi.baidu.com/george_gly/item/5183b76e5a79e49ac5d2498b nat网络模式下,虚拟机可以访问外网.访问 ...

  4. android中actionbar的title居中

    1.配置 activity的主题: android:theme="@style/AppThemeBB" 2. 通过Menu.xml文件布局 添加菜单item menu/menu.x ...

  5. 第三篇 Integration Services:增量加载-Adding Rows

    本篇文章是Integration Services系列的第三篇,详细内容请参考原文. 增量加载是什么增量加载仅加载与先前加载差异的.差异包括:->新增的行->更新的行->删除的行通过 ...

  6. 知识准备-JOIN/EXISTS

    10:40 2013-08-29 JOIN ON...AND A left join B on A.col1=B.col1 and A.col2=xx A left join B on A.col1= ...

  7. iOS 自定义UIButton(图片和文字混合)

    // UIApplicationDelegate  .h文件 #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder &l ...

  8. spring4 文件下载功能

    需要准备的工具和框架 Spring 4.2.0.RELEASE Bootstrap v3.3.2 Maven 3 JDK 1.7 Tomcat 8.0.21 Eclipse JUNO Service ...

  9. nodejs 入门

    1. hello word hello.js console.log("hello"); node hello.js即可 2.调试 如果 npm install太慢 可以使用国内淘 ...

  10. NSNotificationCenter

    - (void)viewDidLoad { [super viewDidLoad]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCust ...