模拟淘宝购物,运用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>

  

  

  

  

时间: 2024-08-11 05:35:20

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

一款仿淘宝购物的商品列表页面多条件查询(含有单选和全部)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

2014双十一淘宝购物省钱攻略

对于网购达人来说,淘宝双11狂欢节是淘宝购物的最佳时机,现在就可以瞄准目标,等到当天就直接下手了,“早起的鸟儿有虫吃”,最明智的做法是在双十一之前提前打折品牌并收藏,对喜欢的商品多进行品质和价格的比较,可以避免冲动消费哦.今天我为大家介绍下2014年淘宝双十一攻略,一起来看看吧! 熟话说的好“磨刀不误砍柴工”,那么我们在开始前需要升级一下自己的武器. 准备工作: 下载并安装 360浏览器 或者 百度浏览器 下载 2014双11爆款折扣内部清单.xlsx (下载地址:http://pan.baid

模拟淘宝登陆和购物车功能

登陆页面代码; <%@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

淘宝购物支付更安全

网上购物已经成为一种必然的趋势,相比实体店的购物,有些人更喜欢待在家里购物,用手机可以随时随地的购物,网上眼花缭乱的东西,让我们目不暇接,当然有好处也有弊端,长时间的观看导致眼睛的疲劳,最重要的在电脑端登录淘宝,在支付环节,容易泄漏个人隐私和个人财产安全,但手机端会大大减小这样的危害,各种各样的手机密码提高了使用安全.又想安全购物又要缓解视力有没有两全其美的方法呢? 最近我发现一软免费的软件可以实现这样的功能.小萝贝控机大师可以把手机连接到电脑端,手机的屏幕投射到电脑上. 连接成功后,可以在电脑

jquery模拟淘宝购物车

今天要实现的一个功能页面就是利用jquery代码模拟一个淘宝网的购物车结算页面 总体页面效果如图: 首先我们要实现的内容的需求有如下几点: 1.在购物车页面中,当选中“全选”复选框时,所有商品前的复选框被选中,否则所有商品的复选框取消选中. 2.当所有商品前的复选框选中时,“全选”复选框被选中,否则“全选”复选框取消选中. 3.单击图标-的时候数量减一而且不能让物品小于0并且商品总价与积分随之改变. 4.单击图标+的时候数量增加并且商品总价与积分随之改变. 5.单击删除所选将删除用户选中商品,单

淘宝购物遇假货

经常在淘宝上买电子产品 以前没注意,知道上次买了一个硬盘 ,半年后无意间打开外壳才发现外壳是WD的里面确实东芝的次品, 商家的广告宣传真的是误导性很大 的: 见广告: 该商家店铺:http://shop71190054.taobao.com/ 按照他们的查询方法确实没问题,是真 的,但是问题在于查询的编码是硬盘的外壳上的,里面的已经掉包了(很多电子产品都是这样造假的,盗用正确的查询码贴在产品上),所以一般很难看得出来是假货. 而且当我们去找商家理论的时候,呵呵,不好意思,你拿他没办法,理由:"

web类似于淘宝购物页面

花了一下午的时间写出来的简易页面,内容很粗糙,但里边包含了我独特的想法.由于是初学者,写的可能不好,希望大家多多提出意见. 这个是主程序 <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>淘宝首页</title> <script type="text/javascript" src="js/jquery-3.

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

<%@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" &

Python 模拟淘宝登录的两种方法

方法一.urllib的post登录 import urllib import urllib2 import cookielib def taobao(username,password): cj = cookielib.CookieJar() print cj post_data = urllib.urlencode( { 'TPL_password':password, 'TPL_username':username, }) path = 'https://login.taobao.com/m