1、登录界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String name="";
//获取所有cookie
Cookie[] ck=request.getCookies();
if(ck!=null)
{
//遍历
for(Cookie co:ck)
{
if(co.getName().equals("name"))
{
name=co.getValue();
}
}
}
%>
请登录购物账号 <form action="Test.jsp" method="post"> 账户:<input type="text" name="name" value="<%=name %>">
密码:<input type="password" name="password"> <input type="submit" value="点击登录"> </form>
</body>
</html>

2,验证登录

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% response.setHeader("Cache-Control", "no-cache"); String name= request.getParameter("name");
String password=request.getParameter("password");
if(name == null || password == null || name.equals("") || password.equals(""))
{ out.write("请正确登录!");
response.setHeader("refresh", "2;url=Denglu.jsp");
}
else{
//验证
if(name.equals("1234")&&password.equals("123456"))
{
//用cookie记住账号
//创建cookie
Cookie coo=new Cookie("name",name);
coo.setMaxAge(20*24*3600);
response.addCookie(coo); //保持登录状态
//创建session
session.setAttribute("name", name);
session.setMaxInactiveInterval(20*60); response.sendRedirect("Gouwuche.jsp");
}
else
{
out.write("用户名或密码错误");
} }
%> </body>
</html>

3.购物界面

<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
淘宝首页
<br>
<% Object obj=session.getAttribute("name"); if(obj==null)
{
out.write("回话超时或未登录");
response.setHeader("refresh", "2;url=Denglu.jsp");
}
else
{
out.write(obj+",欢迎登录"); }
%> <form action="Daoru.jsp" method="post">
请输入您想要购买的商品名称:<input type="text" name="namesp" /><br/>
<input type="submit" value="加入购物车" /><br/>
</form>
<br>
<a href="logout.jsp">退出</a>
</body>
</html>

4.退出界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
//销毁session
session.invalidate(); out.print("退出成功"); response.setHeader("refresh", "2;url=Denglu.jsp"); %>
</body>
</html>

5.创建cookie商品

<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% String namesp=request.getParameter("namesp");
namesp=new String(namesp.getBytes("ISO-8859-1"),"UTF-8");
//设置cookie
Cookie coo = new Cookie("namesp", URLEncoder.encode(namesp) );//利用cookie记住购物车内的物品
//设置cookie的生命周期为10分钟
coo.setMaxAge(600);
//发送cookie
response.addCookie(coo);
//跳转页面到菜单选择
response.sendRedirect("ShangPin.jsp"); %> </body>
</html>

6.购物车内商品

<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object obj=session.getAttribute("name");
if(obj!=null)
{
Cookie[] ck=request.getCookies();
if(ck!=null)
{
for(int i =0 ;i<ck.length;i++){
if(ck[i].getName().equals("namesp")){
out.print(ck[i].getName() + "= " + URLDecoder.decode(ck[i].getValue()) + "<br/>");
}
}
}
else
{
out.write("购物车没有商品") ;
}
}
else
{
out.write("未登录");
}
%>
<a href="Gouwuche.jsp">返回进行购物</a>
</body>
</html>

  

  

  

  

模拟淘宝购物,运用cookie,记录登录账号信息,并且记住购物车内所选的商品的更多相关文章

  1. php单点登录之模拟淘宝天猫同步登录

    说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...

  2. 绝对好评的淘宝购物导航:baiso.uz.taobao.com

    绝对好评的淘宝购物导航:baiso.uz.taobao.com 绝对好评的淘宝购物导航--百搜:http://baiso.uz.taobao.com

  3. 模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能

    Login <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  4. 【Python】selenium模拟淘宝登录

    # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By f ...

  5. SSH框架实现仿淘宝购物demo

    还记得六月份实习的时候,曾经做过一个电商的项目,项目里面需要实现类似淘宝购物车的移动端的demo,随着项目的进行,再一次跟购物车碰面,但是今天呢,不是移动端的需求,如何使用SSH框架实现类似淘宝的购物 ...

  6. selenium模拟淘宝登陆,过所有验证

    淘宝模拟登陆实现 由于淘宝使用了滑动验证码,需要进行模糊手动滑动,因此考虑使用selenium+chromedriver进行模拟登陆. 淘宝的登陆网址:https://login.taobao.com ...

  7. jquery模拟淘宝购物车

    今天要实现的一个功能页面就是利用jquery代码模拟一个淘宝网的购物车结算页面 总体页面效果如图: 首先我们要实现的内容的需求有如下几点: 1.在购物车页面中,当选中“全选”复选框时,所有商品前的复选 ...

  8. Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)

    一.前言 在上篇购物车中,如果用户刷新了当前的页面,底部导航中的数据又会恢复为原来的: 1.解决刷新,购物车上数值不变                                         ...

  9. javascript项目实战之原生js模拟淘宝购物车

    通过JavaScript实现类似与淘宝的购物车效果,包括商品的单选.全选.删除.修改数量.价格计算.数目计算.预览等功能的实现.实现的效果图: 相应的代码: shoppingCart.html < ...

随机推荐

  1. git 查看某文件的修改历史

    前提 先进入此文件所在的目录下 1. git log filename可以看到fileName相关的commit记录2. git log -p filename可以显示每次提交的diff3. 只看某次 ...

  2. 在DirectX9中使用DXUT定制按钮来控制模型旋转的问题

    使用DXUT中的按钮控件类实现 控制模型旋转的过程如下: 1.创建一个CDXUTDialog对话框,并绑定至CDXUTDialogResourceManager对话框资源管理器. 2.绑定回调函数GU ...

  3. jQuery页面加载初始化的3种方法

    jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...

  4. Solr DIH JDBC 源码解析

    Solr DIH 源码解析 DataImportHandler.handleRequestBody()中的importer.runCmd(requestParams, sw) if (DataImpo ...

  5. MongoDB CURD 介绍

    MongoDB是用JSON格式的field和value成对的documents存储数据,documents类似于编程语言中的key value 键值对(例如:dictionaries,hashes,m ...

  6. 图解修改mysql的默认数据库存放目录

    按照下图三步完成:

  7. 一些比较实用的css片段

    新看了一个帖子,里面好多实用的css代码块,可拿出来当做功能库.先附上该文地址http://segmentfault.com/a/1190000002773955 里面的内容很多我挑了几个经过我验证的 ...

  8. css 大话盒子模型

    什么是盒子模型? CSS中, Box Model叫盒子模型(或框模型),Box Model规定了元素框处理元素内容(element content).内边距(padding).边框(border) 和 ...

  9. MySQL慢查询日志总结

    慢查询日志概念 MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long_query_time值的SQL,则会被记录到慢查询日志 ...

  10. problem-eclipse创建maven项目报错

    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...