简单的登录验证程序代码

 

 

 

No.

页面名称

描述

1

login.jsp

提供用户的登陆表单,可以输入用户id和密码。

2

check.jsp

登陆检查页,根据表单提交过来的id和密码进行数据库验证,成功跳转到登陆成功页,否则跳转到登陆失败页。

3

success.jsp

登陆成功页,显示欢迎信息。

4

failure.jsp

登陆失败页,提示用户输入错误,并提供重新登陆的超链接。

1、login.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>Insert title here</title>
</head>
<body>
<form action="check.jsp" method="post">
<input type="text" name="uName">
<input type="text" name="uPwd">
<input type="submit" value="提交">


</form>
</body>
</html>

2、check.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>Insert title here</title>
</head>
<body>
<% 
		String driverName="org.gjt.mm.mysql.Driver"; 
		String userName="root"; 
		String userPasswd="123456"; 
		String dbName="mldn"; 		 
		String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; 
		Class.forName("com.mysql.jdbc.Driver").newInstance(); 
		Connection conn=DriverManager.getConnection(url); 
		PreparedStatement ps = null;
		ResultSet re = null;
	
%>

<%
String uName=request.getParameter("uName");
String uPwd=request.getParameter("uPwd");

String sql  = "select * from vUser where uName=? AND uPwd=?";
ps = conn.prepareStatement(sql);
ps.setString(1, uName);
ps.setString(2, uPwd);


re = ps.executeQuery();



if(re.next()){
%>
<jsp:forward page="success.jsp">
<jsp:param value="<%=uName %>" name="uName"/>
</jsp:forward>

<%} else{%>
<jsp:forward page="fail.jsp"></jsp:forward>


<%} %>

</body>
</html>

3、success.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>Insert title here</title>
</head>
<body>
<h1>登陆成功</h1>
<%
String uName=request.getParameter("uName");
%>
<h1>欢迎<%=uName %>登录</h1>
</body>
</html>

4、fail.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>Insert title here</title>
</head>
<body>
<h1>登录失败</h1>
<a href="index.jsp">请重新登录</a>
</body>
</html>

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值