模拟淘宝购物,运用cookie,记录登录账号信息,并且记住购物车内所选的商品
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,记录登录账号信息,并且记住购物车内所选的商品的更多相关文章
- php单点登录之模拟淘宝天猫同步登录
说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...
- 绝对好评的淘宝购物导航:baiso.uz.taobao.com
绝对好评的淘宝购物导航:baiso.uz.taobao.com 绝对好评的淘宝购物导航--百搜:http://baiso.uz.taobao.com
- 模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能
Login <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- 【Python】selenium模拟淘宝登录
# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By f ...
- SSH框架实现仿淘宝购物demo
还记得六月份实习的时候,曾经做过一个电商的项目,项目里面需要实现类似淘宝购物车的移动端的demo,随着项目的进行,再一次跟购物车碰面,但是今天呢,不是移动端的需求,如何使用SSH框架实现类似淘宝的购物 ...
- selenium模拟淘宝登陆,过所有验证
淘宝模拟登陆实现 由于淘宝使用了滑动验证码,需要进行模糊手动滑动,因此考虑使用selenium+chromedriver进行模拟登陆. 淘宝的登陆网址:https://login.taobao.com ...
- jquery模拟淘宝购物车
今天要实现的一个功能页面就是利用jquery代码模拟一个淘宝网的购物车结算页面 总体页面效果如图: 首先我们要实现的内容的需求有如下几点: 1.在购物车页面中,当选中“全选”复选框时,所有商品前的复选 ...
- Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)
一.前言 在上篇购物车中,如果用户刷新了当前的页面,底部导航中的数据又会恢复为原来的: 1.解决刷新,购物车上数值不变 ...
- javascript项目实战之原生js模拟淘宝购物车
通过JavaScript实现类似与淘宝的购物车效果,包括商品的单选.全选.删除.修改数量.价格计算.数目计算.预览等功能的实现.实现的效果图: 相应的代码: shoppingCart.html < ...
随机推荐
- Puppet自动化部署-安装及配置(3)
本文介绍Puppet Master及Agent相关的安装及配置. 一. 官网下载Puppet安装YUM源 [root@puppet-master ~]# rpm -ivh https://yum.pu ...
- 各大IT技术博客排行榜
cnblogs 积分排名前3000名 http://www.cnblogs.com/ 左侧有推荐博客排行 cppblog http://www.cppblog.com/AllBloggers.aspx ...
- T-SQL Recipes之Customized Database Objects
The Problem 创建灵活自定义对象决非是一个简单的任务.比如HR想看每种工作职称在所有年限里面的入职累计情况 The Solution 我们一步一步来拆解吧: 获取入职年限的集合,如1999, ...
- mysql中生产表格多列统计问题
for Example: select date_format(date,'%Y-%m-%d') as day, count(case when xinghao='a' then 1 end) as ...
- css中关于居中的问题
居中是最常用的一种css格式,不同的居中方法适和不同的环境中,下面总结了几种常用的居中方法,你可以不用它,但是无论你是一个资深前端大牛,还是小小初学者,当你见到它的时候不认识它就是你的不对啦!!! h ...
- 获取IP地址 & 伪装IP地址发送请求
//获取请求客户端IP地址 public final static String getIpAddress(HttpServletRequest request) throws IOExcepti ...
- LL LR SLR LALR 傻傻分不清
[转] 一:LR(0),SLR(1),规范LR(1),LALR(1)的关系 首先LL(1)分析法是自上而下的分析法.LR(0),LR(1),SLR(1),LALR(1)是自下而上的分析法. ...
- cordova插件开发注意事项
1. 编写插件,先创建好cordova项目之后,在项目里开发调试好在去创建插件目录 如何在cordova项目里创建呢,在android文件夹下面的res/xml/config.xml里去加入插件 例如 ...
- iptables 思维导图 (zz)
- Mimikatz 使用Tips
1.记录 Mimikatz输出: C:\>mimikatz.exe ""privilege::debug"" ""log sekurl ...