• form 登陆跳转页面练习(未连接数据库)和连接数据库版


    <%@ 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>
    <style>
    
    .a{500px;height:300px ;border : 1px solid #FF0000 ; left : 240px ; top : 120px ;
            position : relative ;background-color: purple; text-align: center ;}
    </style>
    <body>
    
    <hr>
    <font style="text-shadow: 3px 3px 3px #FF0000">
    不会连接数据库,所以先默认账号123,默认密码000,做练习
    </font>
    <hr>
    <div class="a">
    <h1>银行自助终端系统</h1>
    
    <form action="NewFile1.jsp" method="get">
    卡号<input type="text"  name="name"><br>
    <br><br>
    密码<input type="password"  name="password"><br>
    <br><br>
    <input type="reset" value="重置" >  
    <input type="submit" value="登陆">
    </form>
    
    </div>
    </body>
    </html>
    <%@page import="java.sql.SQLException"%>
    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.DriverManager"%>
    <%@page import="java.sql.Connection"%>
    <%@ 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>
    <%
    String name = request.getParameter("name") ;
    
    name = new String(name.getBytes("ISO-8859-1") , "UTF-8" ) ;
    
    String password = request.getParameter("password") ;
    
    out.write("<br>收到的参数<br>用户名:"+name+"<br> 密码:"+password+"<br>") ;
    
    if(name.equals("123"))
    {
        if(password.equals("000"))
        {
    %>
            <!-- 账号密码正确跳转登陆页面-->
            <jsp:forward page="success.jsp"></jsp:forward>
    <% 
        }
        else
        {
    %>
            <!-- 账号正确密码错误跳转密码错误提示页面 -->
            <jsp:forward page="failpassword.jsp"></jsp:forward>
    <% 
        }
    }
    else
    {
    %>
        <!-- 账号错误跳转账号错误提示页面 -->
        <jsp:forward page="failkahao.jsp"></jsp:forward>
    <% 
    }
    
    %>
    <!-- 
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver") ;
        
        String url ="jdbc:oracle:thin:@localhost:1521:orcl" ;
        
        Connection conn = DriverManager.getConnection(url,"test0816","934617699") ;
        
        String sql = "select * from account_bank where kahao= ? " ;
        
        PreparedStatement ps = conn.prepareStatement(sql) ;
        
        ps.setString(1, name);
        
        ResultSet rs = ps.executeQuery() ;
        
        if(rs.next())
        {
            if(password.equals(rs.getString("passqord")))
            {
                //out.write("登陆成功") ;
            }
            else
            {
                //out.write("密码错误") ;
            }
        }
        else
        {
            out.write(22) ;
            //out.write("账号错误") ;
        }
    } catch (Exception e) {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
    }
     -->
    </body>
    </html>
    <%@ 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>
    
    <h2>当输入账号错误的时候跳转该到页面</h2>
    <br>
    <h1>卡号不存在!!!!!!</h1>
    </body>
    </html>
    <%@ 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>
    <h2>当输入密码错误的时候跳转到该页面</h2>
    <br>
    <h1>密码错误!!!!!!</h1>
    </body>
    </html>
    <%@ 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>
    <br>
    <h1>登陆成功!</h1>
    
    </body>
    </html>

    账号不对时

    卡号正确,密码错误的时候

    当密码卡号都正确时

     ==================================连接数据库版======================================

    <%@page import="java.sql.SQLException"%>
    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.DriverManager"%>
    <%@page import="java.sql.Connection"%>
    <%@ 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>
    <%
    String name = request.getParameter("name") ;
    
    name = new String(name.getBytes("ISO-8859-1") , "UTF-8" ) ;
    
    String password = request.getParameter("password") ;
    
    out.write("<br>收到的参数<br>用户名:"+name+"<br> 密码:"+password+"<br>") ;
    
    
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver") ;
        
        String url ="jdbc:oracle:thin:@localhost:1521:orcl" ;
        
        Connection conn = DriverManager.getConnection(url,"test0816","934617699") ;
        
        String sql = "select * from account_bank where kahao= ? " ;
        
        PreparedStatement ps = conn.prepareStatement(sql) ;
        
        ps.setString(1, name);
        
        ResultSet rs = ps.executeQuery() ;
        
        if(rs.next())
        {
            if(password.equals(rs.getString("password")))
            {
        %>
                <!-- 账号密码正确跳转登陆页面-->
                <jsp:forward page="success.jsp"></jsp:forward>
        <% 
            }
            else
            {
                %>
                <!-- 账号正确密码错误跳转密码错误提示页面 -->
                <jsp:forward page="failpassword.jsp"></jsp:forward>
        <%
            }
        }
        else
        {
            %>
            <!-- 账号错误跳转账号错误提示页面 -->
            <jsp:forward page="failkahao.jsp"></jsp:forward>
        <% 
        }
    } catch (Exception e) {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
    }
    %>
    </body>
    </html>

  • 相关阅读:
    微软算法100题25 查找连续最长的数字串
    微软算法100题24 就地逆序单链表
    微软算法100题21 数列中所有和为特定值的组合
    微软算法100题20 字符串转整数 atoi
    约瑟夫环
    微软算法100题17 字符串中找到第一个只出现一次的字符
    微软算法100题16 按层遍历二叉树
    微软算法100题15 求二元查找树的镜像
    微软算法100题14 在排序数组中找到和为指定数的任意两个元素
    NLP(十) 主题识别
  • 原文地址:https://www.cnblogs.com/20gg-com/p/6009240.html
Copyright © 2020-2023  润新知