简单的登录实现

<span style="font-size:18px;">登录页面</span>
<span style="font-size:18px;"></span><pre name="code" class="java"><%@page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>河南</title></head>
<body>
<center>
<h1>登陆操作</h1>
<hr>
	<form action="login_check.jsp" method="post">
		<table border="1">
			<tr>
				<td colspan="2">
					用户登陆
				</td>
			</tr>
			<tr>
				<td>登陆ID:</td>
				<td><input type="text" name="id"></td>
			</tr>
			<tr>
				<td>登陆密码:</td>
				<td><input type="password" name="password"></td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="登陆">
					<input type="reset" value="重置">
				</td>
			</tr>
		</table>
	</form>
</center>
</body>
</html>

检查页面
 
<span style="font-size:18px;"></span><pre name="code" class="java"><%@page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<html>
<head><title>河南</title></head>
<body>
<center>
<h1>登陆操作</h1>
<hr>
<%!	// 定义若干个数据库的连接常量
	public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
	public static final String DBURL = "jdbc:mysql://localhost:3306/mldn" ;
	public static final String DBUSER = "root" ;
	public static final String DBPASS = "admin" ;
%>
<%
	Connection conn = null ;		// 数据库连接
	PreparedStatement pstmt = null ;	// 数据库预处理操作
	ResultSet rs = null ;		// 查询要处理结果集
	boolean flag = false ;	// 保存标记
	String name = null ;	// 保存真实姓名
%>
<%
try{
%>
<%
	Class.forName(DBDRIVER) ;
	conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
	String sql = "SELECT name FROM user WHERE userid=? AND password=?" ;
	pstmt = conn.prepareStatement(sql) ;
	pstmt.setString(1,request.getParameter("id")) ;
	pstmt.setString(2,request.getParameter("password")) ;
	rs = pstmt.executeQuery() ;	// 查询
	if(rs.next()){	// 如果有数据,则可以执行
		flag = true ;	//  表示登陆成功
		name = rs.getString(1) ;
	}	
%>
<%
}catch(Exception e)	{
	e.printStackTrace() ;
}
finally{
	try{
		rs.close() ;
		pstmt.close() ;
		conn.close() ;
	} catch(Exception e){}
}
%>
<%
	if(flag){	// 登陆成功
%>
		<jsp:forward page="login_success.jsp">
			<jsp:param name="uname" value="<%=name%>"/>
		</jsp:forward>
<%
	} else {		// 登陆失败
%>
		<jsp:forward page="login_failure.jsp"/>
<%
	}
%>
</center>
</body>
</html>
成功页面
 
<span style="font-size:18px;"></span><pre name="code" class="java"><%@page contentType="text/html" pageEncoding="GBK"%>
<html>
<head><title>河南</title></head>
<body>
<center>
<h1>登录操作</h1>
<h2>登录成功</h2>
<h2>欢迎<font color="red"><%=request.getParameter("uname")%></font>光临</h2>
</center>
</body>
</html>


 
<span style="font-size:18px;">页面截图</span>
<span style="font-size:18px;"><img src="https://img-blog.csdn.net/20150601110647945?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3dhbnpodQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><img src="https://img-blog.csdn.net/20150601110531761?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3dhbnpodQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</span>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值