用JSP实现WEB页面登录验证
来源:互联网 发布:安卓上传图片 php 编辑:程序博客网 时间:2024/09/21 08:56
1.index.html
<!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>系统登录</title>
</head>
<body>
<center>
<h2>系统登录</h2>
<form action="login.jsp" method="post">
<input type="text" name="uid" maxlength=8 style="width:150"><br>
<input type="password" name="upwd" maxlength=8 style="width:150"><br>
<input type="submit" value="登录">
<input type="reset" value="取消">
</form>
</center>
</body>
</html>
2.login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.* "%>
<!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>验证页面</title>
</head>
<body>
<%
String user_name= request.getParameter("uid");
String pass_word = request.getParameter("upwd");
if(user_name!=null && !user_name.equals("")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","test","test");
Statement stmt=(Statement)conn.createStatement();
String sql="select * from account where username='"+user_name+"'";
sql +="and password='"+pass_word+"'";
ResultSet rs=(ResultSet)stmt.executeQuery(sql);
if(rs.next())
{
session.setAttribute("login","ok");
session.setAttribute("uname",user_name);
%>
<jsp:forward page="main.jsp"/>
<%
}else out.println("错误的用户名和密码");
out.println("<a href=index.html>返回</a>");
}catch(Exception ee){ee.printStackTrace();}
}else{
out.println("请先登录");
out.println("<a href=index.html>返回</a>");
}
%>
</body>
</html>
3.main.jsp
<%@ 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>主页面</title>
</head>
<body>
<%@include file="checkvalid.jsp"%>
欢迎进入本页面,您已经通过了验证,你的用户名是:<%=session.getAttribute("uname") %><p>
<a href=continue.jsp>您可以跳转到后续页面</a>
</body>
</html>
4.checkvalid.jsp
<%@ 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>验证页面</title>
</head>
<body>
<%
if(session.getAttribute("login")==null||!session.getAttribute("login").equals("ok"))
{response.sendRedirect("index.html");}
%>
</body>
</html>
5.continue.jsp
<%@ 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>二级页面</title>
</head>
<body>
<%@include file="checkvalid.jsp"%>
<%=session.getAttribute("uname") %>,欢迎您进入第二个页面!<p>
</body>
</html>
<!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>系统登录</title>
</head>
<body>
<center>
<h2>系统登录</h2>
<form action="login.jsp" method="post">
<input type="text" name="uid" maxlength=8 style="width:150"><br>
<input type="password" name="upwd" maxlength=8 style="width:150"><br>
<input type="submit" value="登录">
<input type="reset" value="取消">
</form>
</center>
</body>
</html>
2.login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.* "%>
<!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>验证页面</title>
</head>
<body>
<%
String user_name= request.getParameter("uid");
String pass_word = request.getParameter("upwd");
if(user_name!=null && !user_name.equals("")){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","test","test");
Statement stmt=(Statement)conn.createStatement();
String sql="select * from account where username='"+user_name+"'";
sql +="and password='"+pass_word+"'";
ResultSet rs=(ResultSet)stmt.executeQuery(sql);
if(rs.next())
{
session.setAttribute("login","ok");
session.setAttribute("uname",user_name);
%>
<jsp:forward page="main.jsp"/>
<%
}else out.println("错误的用户名和密码");
out.println("<a href=index.html>返回</a>");
}catch(Exception ee){ee.printStackTrace();}
}else{
out.println("请先登录");
out.println("<a href=index.html>返回</a>");
}
%>
</body>
</html>
3.main.jsp
<%@ 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>主页面</title>
</head>
<body>
<%@include file="checkvalid.jsp"%>
欢迎进入本页面,您已经通过了验证,你的用户名是:<%=session.getAttribute("uname") %><p>
<a href=continue.jsp>您可以跳转到后续页面</a>
</body>
</html>
4.checkvalid.jsp
<%@ 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>验证页面</title>
</head>
<body>
<%
if(session.getAttribute("login")==null||!session.getAttribute("login").equals("ok"))
{response.sendRedirect("index.html");}
%>
</body>
</html>
5.continue.jsp
<%@ 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>二级页面</title>
</head>
<body>
<%@include file="checkvalid.jsp"%>
<%=session.getAttribute("uname") %>,欢迎您进入第二个页面!<p>
</body>
</html>
- 用JSP实现WEB页面登录验证
- jsp页面登录验证
- jsp页面验证登录账号
- 单java+2jsp页面实现登录验证
- Bootstrap+web+Idea实现登录页面(含验证码)
- .net登录页面实现验证码验证
- WEB登录页面加入简单验证码
- jsp web登录页面压力测试
- JSP登录页面包括验证码的验证
- JSP登录页面包括验证码的验证
- JSP登录验证功能的实现
- javaBean+jsp+mysql实现登录验证
- JSP带验证码的登录实现
- java jsp实现登录验证码
- jsp登录验证码功能实现
- JSP + Servlet实现登录验证码
- jsp实现登录验证的过滤器
- servlet+jsp实现验证码登录
- Java通用工具类(二)-----日期处理
- 关于JS通过正则表达式循环检测多个Email格式_已经测试通过.
- Java:接口与抽象类
- Delphi之面向对象程序开发
- 2006/11/25
- 用JSP实现WEB页面登录验证
- 关于在线重定义表
- vista试用记(二)
- 打算减肥的朋友们一定要看的----18种食物让你越吃越瘦
- B/S系统权限控制的一种简单方法
- 团队开发中多个STRUTS,SPRING的解决方案
- CORBA 入门
- 深圳租房完全攻略
- 谈谈javascript类(转)