Use cookies to query product browsing records and cookies
After two weeks, the yimei.com project was completed on schedule. Now we will summarize how to use cookies to view the history of commodities.
Step 1: Create a commodity entity class.
Step 2: connect to the oracle database.
Step 3: Create a three-tier product architecture.
:
Add the core code to the display area:
<H2> recently viewed
Click to view the product details page. The Code is as follows:
<% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; // obtain the item idrequest. setCharacterEncoding ("UTF-8"); String book = request. getParameter ("id"); Cookie [] cookies = request. getCookies (); List <Cookie> cookieList = new ArrayList <Cookie> (); Cookie tempCookie = null; // filter cookieif (cookies! = Null & cookies. length> 0) {for (Cookie c: cookies) {String cookieName = c. getName (); if (cookieName. startsWith ("product-view") {cookieList. add (c);} if (c. getValue (). equals (book) {tempCookie = c ;}} if (cookieList. size ()> = 10 & tempCookie = null) {tempCookie = cookieList. get (0);} Cookie cookie = new Cookie ("product-view" + book, book); response. addCookie (cookie); %>
In this way, browsing records of commodities are realized.