模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能
Login <%@ 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>
<%
//提取cookie保存的卡号
Cookie[] cc=request.getCookies();
String cardid="";
if(cc!=null)
{
//遍历
for(Cookie c:cc)
{
if(c.getName().equals("cardid"))
{
cardid=c.getValue();
}
}
}
%>
<form action="check.jsp" method="post">
卡号:<input type="text" name ="cardid" value="<%=cardid%>">
<br>
密码:<input type="password" name="password">
<br>
<input type="submit" value="登陆">
</form>
</body>
</html>
check <%@ 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 cardid =request.getParameter("cardid");
String password =request.getParameter("password");
if(cardid == null || password ==null || cardid.equals("") || password.equals(""))
{
out.print("成功");
response.setHeader("refresh", "3;url=Login.jsp");
}
else
{ //验证
if(cardid.equals("cardid")&&password.equals("password"))
{
//用cookie记住卡号
Cookie cid= new Cookie("cardid",cardid);
cid.setMaxAge(60*60); //设置cookie存在的时间
response.addCookie(cid);
//保持登录状态
session.setAttribute("cardid", cardid);
response.sendRedirect("Main.jsp");
}
else
{
out.print("错误");
response.setHeader("refresh", "3;url=Login.jsp");
}
}
%>
</body>
</html>
main <%@ 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("cardid");
if(obj==null)
{
out.print("会话超时或未登录"); response.setHeader("regfresh","3;url=Login.jsp");
}
else
{
out.print(obj+"登录成功");
}
%>
<br>
<br>
<a href="Logout.jsp">退出登录</a>
</body>
</html>
Logout <%@ 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=Login.jsp");
%>
</body>
</html>
模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能的更多相关文章
- 工作任务:模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能
登入界面<% Cookie[] cks =request.getCookies(); String str=null; for(Cookie ck:cks) { if(ck.getName(). ...
- php单点登录之模拟淘宝天猫同步登录
说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...
- 模拟淘宝购物,运用cookie,记录登录账号信息,并且记住购物车内所选的商品
1.登录界面 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...
- jquery模拟淘宝购物车
今天要实现的一个功能页面就是利用jquery代码模拟一个淘宝网的购物车结算页面 总体页面效果如图: 首先我们要实现的内容的需求有如下几点: 1.在购物车页面中,当选中“全选”复选框时,所有商品前的复选 ...
- 【Python】selenium模拟淘宝登录
# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By f ...
- 模拟淘宝使用cookie记录登录名,
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- javascript项目实战之原生js模拟淘宝购物车
通过JavaScript实现类似与淘宝的购物车效果,包括商品的单选.全选.删除.修改数量.价格计算.数目计算.预览等功能的实现.实现的效果图: 相应的代码: shoppingCart.html < ...
- Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)
一.前言 在上篇购物车中,如果用户刷新了当前的页面,底部导航中的数据又会恢复为原来的: 1.解决刷新,购物车上数值不变 ...
- selenium模拟淘宝登陆,过所有验证
淘宝模拟登陆实现 由于淘宝使用了滑动验证码,需要进行模糊手动滑动,因此考虑使用selenium+chromedriver进行模拟登陆. 淘宝的登陆网址:https://login.taobao.com ...
随机推荐
- js跳转到新页面传参以及接收参数的方法
1.传递参数: window.location.href = "./list.html?id="+id; 1.接收参数: (1)接收参数函数封装 function GetReque ...
- 猿团YTFCloud--5分钟自制APP,开发从未如此简单
9月15日,YTFCloud将正式开启内测, 这意味着猿团YTF框架产品线全面升级.同时,公测过后,YTFCloud的APP线上DIY服务将面向所有用户,让人人都能成为APP“开发商”. 什么是YTF ...
- 【ImageView】ImageView点击事件报错空指针
今天在使用自定义圆形imageview的时候,想利用其点击事件来实现查看个人资料功能,但是该空间在Activity中的onCreate方法中调用点击事件总是出现空指针异常,每次程序都进不去主页面,到处 ...
- .NET 4.5+项目迁移.NET Core的问题记录
.NET 4.5+项目迁移.NET Core的问题记录 这几天试着把目前的开发框架迁移到新的.net core平台,中间遇到的问题在这里简单记录一下. 迁移过程遇到的最大的问题IOC容器.我目前使用的 ...
- jQuery实现锚点平滑定位
一般的锚点,就是点击一个按钮或者其他元素可以实现定位效果,当然可以使用锚点实现,但是这个不够美观,没有平滑的动画过渡效果,下面就通过代码实例介绍一下利用jquery实现平滑的定位效果. <!DO ...
- struts2 validation.xml 注意点
1.首先应该注意validation.xml的名字,一定要以Action的类名加“-validation.xml”作为文件名.入LoginAction-validation.xml. 2.LoginA ...
- WebBench源码分析与心得
源码:https://github.com/EZLippi/WebBench 关键全局变量: speed 成功次数 failed 失败次数 bytes 接收字节数 benchtime 执行时长(秒 ...
- Hyper-V初涉:功能的添加与虚拟机的创建
Hyper-V是微软提供的一款高效率的虚拟化管理软件,在早期的Windows服务器中配备Hyper-V组件,Windows 8是首次将企业用Hyper-V集成在个人系统中,可见虚拟化技术的发展之迅速. ...
- LintCode 366 Fibonacci
/* 1st method will lead to time limit *//* the time complexity is exponential sicne T(n) = T(n-1) + ...
- zabbix_agentd.conf文件说明
由于工作中经常接触到zabbix,所以将agent配置整理一下,方便日常查看. # This is a config file for the Zabbix agent daemon (Unix) # ...