用户登录页面——jdbc
登录页面程序login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head> <title>登录页面</title> </head>
<body>
<form action="receive.jsp" method="post">
<table>
<tr><td>用户</td><td><input type="text"name="user"></td></tr>
<tr><td>密码</td><td><input type="password"name="password"></td></tr>
<tr align="center">
<td colspan="2">
<input type="submit"value="登 录">
<input type="reset"value="取 消 ">
</td>
</tr>
</table>
</form>
</body>
</html>
检验输入信息程序receive.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
<html>
<head> <title>验证页面</title> </head>
<body>
<%
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPwd="123456";
String dbName="student";
String url1="jdbc:mysql://localhost:3306/student";
String url2="?user=root&password=123456";
String url3="&userUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?user=root&password=123456&userUnicode=true&characterEncoding=UTF-8");
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("user");
String password=request.getParameter("password");
session.setAttribute("user",name);
session.setAttribute("password",password);
String sql="select *from student where name=? and password=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2,password);
ResultSet rs=pstmt.executeQuery();
if(rs.next())
{
if(rs!=null){rs.close();}
if(pstmt!=null){pstmt.close();}
if(conn!=null){conn.close();}%>
<jsp:forward page="succeed.jsp"/>
<%} else { %>
<jsp:forward page="failed.jsp"/>
<%
if(rs!=null){rs.close();}
if(pstmt!=null){pstmt.close();}
if(conn!=null){conn.close();}
%>
<%} %>
</body>
</html>
登陆成功页面succeed.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head> <title>成功页面</title> </head>
<body>
<%String Name=request.getParameter("user"); %>
欢迎,<%=Name %>成功登陆!
</body>
</html>
登陆失败页面failed.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head> <title>失败页面</title> </head>
<body>
登陆失败!
<%String Name=request.getParameter("user"); %>
<br><a href="login.jsp">请重新登录,<%=Name %>同学!
</body>
</html>
时间最会骗人,但也能让你明白,这个世界上没有什么是不能失去的,留下的尽力珍惜,得不到的都不重要
浙公网安备 33010602011771号