package cn.itcast;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry; import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class CookieDemo extends HttpServlet { /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
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("本站所有商品<br/>");
Map<String,Book> map=Db.getAll();
for(Entry<String, Book> entry: map.entrySet()){
Book book=entry.getValue();
out.print("<a href='/day01/servlet/CookieDemo2?id="+book.getId()+"' target='_blank'>"+book.getName()+"</a></br>"); }
//显示用户看过的商品
out.print("<br/>看过的商品<br/>");
Cookie cookies[]=request.getCookies();
for(int i=0;cookies!=null&&i<cookies.length;i++){
if(cookies[i].getName().equals("bookHistory")){
String ids[]=cookies[i].getValue().split("\\,");
for(String id:ids){
Book book=(Book) Db.getAll().get(id); out.print(book.getName()+"<br/>");
}
}
} } /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet( request,response);
} }
//模拟 数据库
class Db{
private static Map<String, Book> map =new LinkedHashMap();
static{
map.put("1", new Book("1","java开发1","zsan1","一本好书1"));
map.put("2", new Book("2","java开发2","zsan2","一本好书2"));
map.put("3", new Book("3","java开发3","zsan3","一本好书3"));
map.put("4", new Book("4","java开发4","zsan4","一本好书4")); }
public static Map getAll(){
return map;} }
class Book{
private String id;
private String name;
private String author;
private String desc; public Book() {
super();
// TODO Auto-generated constructor stub
}
public Book(String id, String name, String author, String desc) {
super();
this.id = id;
this.name = name;
this.author = author;
this.desc = desc;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
} }
package cn.itcast;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class CookieDemo2 extends HttpServlet { /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//根据用户带过来的id显示相应的详细信息
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
out.write("本站所有商品<br/>");
String id=request.getParameter("id");
Book book=(Book) Db.getAll().get(id);
out.write(book.getDesc());
//2.构建cookie,回写给浏览器
String cookieValue=bulidCookie(id,request);
Cookie cookie=new Cookie("bookHistory",cookieValue);
cookie.setMaxAge(30*24);
cookie.setPath("/day01");
response.addCookie(cookie); } private String bulidCookie(String id, HttpServletRequest request) {
// TODO Auto-generated method stub
String bookHistory=null;
Cookie cookies[]=request.getCookies();
for(int i=0;cookies!=null&&i<cookies.length;i++){
if(cookies[i].getName().equals("bookHistory")){
bookHistory=cookies[i].getValue();
} }
if(cookies==null)
{
return id;
}
LinkedList<String> list= new LinkedList(Arrays.asList(bookHistory.split("\\,")));
if(list.contains(id)){
list.remove(id);
list.addFirst(id); }
else
{
if(list.size()>=3){
list.removeLast();
list.addFirst(id);
}
else{
list.addFirst(id);
}
}
StringBuffer sb=new StringBuffer();
for(String bid: list){
sb.append(bid+","); }
return sb.deleteCharAt(sb.length()-1).toString(); } /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doGet( request,response);
} }

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQwAAAC2CAIAAACjyCRjAAAIjklEQVR4nO3d223rOBSFYdbFglgPq1Ez6sEPBgwEAQyfB1kW74u65CSW/w/BTEYWbWWwV0jqwpgHgCbz2wcA/HWEBBAICSAQEkAgJIBASACBkADCupAMzlg/1l8fvTXGDcXtzYaPwRmTNx29NaXtfe/Ze3RA07EhqZVupaCnZBhjzPJqsK2SjmW/1QXfG9Y6MvaB6iFR5VIrnVL11kOSba3mcM3xGDes2n054NavgdFbQvKJ1vQkc90VC2UeGRVLL3txKsRVIUk/a0W55u85eluNIiFBrD8kgzPOOWOdq9RXgx5uvULVN6LbMht5NZmOZhgJCbr0hmQqnumfo7elWgnHWUkqOoZbc2sVEjWMSj61Q/RxzEmQ6QvJXLnBvwvVEtR3UurrQlIv5NbZrvxjot/8r0OOdsoOjJ4EmY6QBIW0lFCpmJYd03La1pMUat64QfQPhZBMLdwwjkE0pj3Xn0fG55EhiU5Wlao6EFblUp31MYuYk0QV/Nre+H1e6km8t8Y6lx2Ide75QtD7FY+zth2foh2SwcVD9rj/yE8yPV+fhzal39NBttLhkHFD1KR+zWXtcCttEyUuDMmy09Ik/qE3XZ/BW6uHZB6khNuyQdbgTF5ZxRIMW5RCkr/cCMm64RYhwS7VkCzFUD3h87rYUZv7ipAUpv9RCR7bkxQPnpBAO/q2lDBT03ygGpLiJb60TleHJHip3pNEuxAStB0WkiAbUaGVuKH0XtkUpzckYVeXtq/Uc9AkmhWVJ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9ctvVmH5tV8rQPrWNYMQZ7kDUfr3lt6y9sN0nS2I8Vp6v9E6t1RQ9SPcXvW3bf07v82jrMXjtb7gta1sAw/HuXerAdv6V0nTEbC92XNkPqJ7sv6yi295pTtyW7ImsHHQ92W9bVbepcphhjr71yuZl28IfAp8bE++uV5+TNQoxd4FGe9d/nPMdSo/BE+mPXZXYGXByHAzwcvTHVPZbtn6YxnIGuYuN4agsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagsgagv4BEFg/XxQ+e0IAAAAASUVORK5CYII=" alt="" />

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOIAAADjCAIAAAAXLl8lAAALxUlEQVR4nO2dTU7zOhRAsw6W4kUwYwteAqPugEmmiDFLIBIDlgAbiARDZiAhISEk1DdI0/jn2rH78dPrd46q90piJ+mX03ttJ266bQ2D7Uw/5kqMvRGKyEu3g+1m9mudZV3X2SFzKJm1VUeXOCSR6l3Cd9Al16ydsNTJk/xJaxotTX4Tao6ns0NV8eWAc1/EsTdo+jekNY2Zz7x4qsbepE9+tHJSoUrTcF8VwsTbHHuT/DKg6fFRrulgO2ttZ6xNnOEM60l/r3VZu2Jd5UyV6WiGEU3VUKrpdPqm/469kc6Wm+0DLwuS/lx7TdO1ZB7stQBvd7RNj5IyTWd3nP8L58sxLJCtTtO0SrN4CVmEL4fb6Jzee4WiAyOaHiUFmjqncjmJ0ulcCoYn9LBoKljX2WElRgqaTjXsMI6OnFPJ9a4/HAOrmnodd8krB9eLxY905lxpm3oO7ZdnYpoUTfvedMba6ECMtbsVTgYQjzO1HH6PvKaD9ZtufgyNO9y79XOClWKVY3eYlDs7eFXSY7C1ST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qCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEBaAoKQFNQAJqCAtAUFICmoAA0BQWgKSgATUEB/wHd9s8SglQFqQAAAABJRU5ErkJggg==" alt="" />

Cookie应用--显示看过的商品的更多相关文章

  1. Cookie案例-显示商品浏览历史纪录

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

  2. 第一百八十七节,jQuery,知问前端--cookie 插件,注册成功后生成cookie,显示登录状态

    jQuery,知问前端--cookie 插件 学习要点: 1.使用 cookie 插件 2.注册直接登录 Cookie 是网站用来在客户端保存识别用户的一种小文件.一般来用库可以保存用户登 录信息.购 ...

  3. 本地文件直接访问html,document.cookie总是显示空字符串

    当file:///E:/browser.html访问时,我们设置document.cookie,读取时一直会显示空字符串! 而开一下Apache时:localhost/browser.html或者12 ...

  4. cookie使用举例(添加购物车商品_移除购物车商品)

    之前介绍过cookie和session的原理和区别.下面举例说明一下cookie在实际项目中的使用.使用cookie实现购物车功能: 1.往购物车添加商品 2.从购物车里移除商品 主要是要点是:以产品 ...

  5. 使用Cookie实现显示用户上次访问时间

    一. 常用Cookie API介绍 1. 获取cookie request.getCookies();  // 返回Cookie[] 2. 创建cookie Cookie(String key, St ...

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

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

  7. session和cookie的区别和联系详解,Cookie Session相关看这篇就够了。

    本文转自:91博客:原文地址:http://www.9191boke.com/199015867.html 有一朋友做面试官的时候,曾经问过很多朋友这个问题: Cookie 和 Session 有什么 ...

  8. cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value

    创建Cookie,名为lasttime,值为当前时间,添加到response中: 在A.jsp中获取请求中名为lasttime的Cookie: 如果不存在输出“您是第一次访问本站”,如果存在输出“您上 ...

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

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

随机推荐

  1. 【转载】GitHub详细教程

    1 Git详细教程   1.1 Git简介   1.1.1 Git是何方神圣?   Git是用C语言开发的分布版本控制系统.版本控制系统可以保留一个文件集合的历史记录,并能回滚文件集合到另一个状态(历 ...

  2. 解决Struts中文乱码问题总结

    在进行struts开发的过程中.总也是出现非常多的乱码问题.但归根究竟,也仅仅是下面三种情况:  ㈠页面显示中文乱码  ㈡传递參数中文乱码  ㈢国际化资源文件乱码  以下就这三中情况介绍怎么在详细项目 ...

  3. 千千万万的IT开发project师路在何方

    已经找不到该文章的最初出处了,有找到的人请告诉我.谢谢~~ 千千万万的IT开发project师路在何方 2007-06-25 21:41 恭喜,你选择开发project师作为自已的职业! 悲哀.你选择 ...

  4. Sqlite 命令行导出、导入数据(直接支持CSV)

    打开命令行 导出数据到data.csv D:\project>sqlite3.exe old.db SQLite version 3.21.0 2017-10-24 18:55:49 Enter ...

  5. Ubuntu 13.04/CentOS 6.4 下C++开发时的相关设置

    Ubuntu 13.04/CentOS 6.4 下C++开发时的相关设置 一.基本设置 首先,为了可以使我们的c++ 可以找到 iostream类,std标准库,我们需要在C/C++ General- ...

  6. Spring Security Architecture--官方

    原文地址:https://spring.io/guides/topicals/spring-security-architecture/ Table of contents Authenticatio ...

  7. gym 100735I

    Description standard input/outputStatements You are given three numbers. Is there a way to replace v ...

  8. mpvue 开发小程序

    转换成vue语法, 小程序中原生的事件用@ 原生的属性用:

  9. 对比了解Grafana与Kibana的关键差异

    对比了解Grafana与Kibana的关键差异 http://www.infoq.com/cn/articles/grafana-vs-kibana-the-key-differences-to-kn ...

  10. &lt;LeetCode OJ&gt; 20. Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...