首页 技术 正文
技术 2022年11月21日
0 收藏 377 点赞 5,041 浏览 2454 个字
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" rel="external nofollow" >退出登录</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>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,913
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,438
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,252
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,063
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,695
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,733