zoukankan      html  css  js  c++  java
  • 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>
    

      

     

      

      

      

      

  • 相关阅读:
    linux中fork()函数详解(原创!!实例讲解) (转载)
    超级课程表原理解析(如何获取网页内容)
    MySql中时间类型总结
    android Json详解
    Jsoup解析Html中文文档
    Mysql相关
    Chrome驱动安装问题
    Airtest 网易 UI 自动化工具 Airtest 浅用记录
    关于Airtest的使用探索
    Sublime text 3搭建Python开发环境及常用插件安装
  • 原文地址:https://www.cnblogs.com/201906mwwan/p/14642750.html
Copyright © 2011-2022 走看看