jsp第六次作业

数据库

 


登陆页面
index.jsp

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>www.school.com</title>
</head>
<body>
	
		<h1>登录</h1>
		<hr>
		<form action="DL.jsp" method="post">
			
				<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="登录"> 
						
				</tr>
			</table>
		</form>
	
</body>
</html>
判断验证页面
DL.jsp
<%@page import="java.nio.channels.SeekableByteChannel"%> <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <html> <head> <title>www.school.com</title> </head> <body> <%!public static final String DBDRIVER = "com.mysql.jdbc.Driver"; public static final String DBURL = "jdbc:mysql://localhost:3306/text"; public static final String DBUSER = "root"; public static final String DBPASS = "201906";%> <% 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 dome WHERE uid=? AND upwd=?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, request.getParameter("id")); pstmt.setString(2, request.getParameter("password")); rs = pstmt.executeQuery(); if (rs.next()) { name = rs.getString(1); flag = true; } } catch (Exception e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); if (pstmt != null) pstmt.close(); if (conn != null) conn.close(); if (flag) { request.getRequestDispatcher("CG.jsp").forward(request, response); } else { response.sendRedirect("YH.jsp"); } } catch (Exception e) { e.printStackTrace(); } } %> </body> </html>>
成功页面

CG.jsp



<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
	<title>www.school.com</title>
</head>
<body>

	
	<h1>登录成功</h1>
	<h1>欢迎来到本页<font color="red">
	
	

</body>
</html>
登录失败返回登录页面
YH.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="3;url=index.jsp">
    <title>登录失败</title>
    <script type="text/javascript">
        function info() {
//循环执行,1秒执行一次
            window.setInterval("daojishi()", 1000);
        }
        function daojishi() {
            if(document.getElementById("msg").innerHTML!=1){
                document.getElementById("msg").innerHTML=document.getElementById("msg").innerHTML-1;
            }
        }
    </script>
</head>
<body "info()">
<h1>用户名或密码错误,</h1><span id="msg"></span><h1>3秒返回登录页面</h1>
</body>
</html>

  

 

 

  

  

  

  

posted on 2021-04-11 00:27  mashao  阅读(33)  评论(0编辑  收藏  举报

导航