• 制作一个银行卡用户登录页面,提交后连接数据库进行登录验证,根据验证结果跳转到不同页面


    Login.jsp

    <%@ 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>
    
    
    <form action="check.jsp" method="post"><!--action里面写要转的jsp页面  -->
    卡号:<input type="text" name="cardid"><br>
    密码:<input type="password" name="password"><br>
    <input type="submit" value="登陆"><br>
    
    
    </form>
    
    </body>
    </html>

    check.jsp   ojdbc6.jar 放lib里

    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.DriverManager"%>
    <%@page import="java.sql.Connection"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@ 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>
    <!--这个页面是
    接收用户输入的卡号和密码,进行验证,验证需要连数据库  
    request对象负责接收-->
    
    <%
        //接收数据
        String cardid=request.getParameter("cardid");
        String password=request.getParameter("password");
        //前两部接收数据,接受完了,就该验证数据
        //一定要确定数据收到了
        //数据验证     检查用户名 密码
        if(cardid==null||password==null
        ||cardid.equals("")||password.equals(""))//得保证都有数据???
        {
            out.write("请正确登陆系统");
        }
        else
        {
            out.write(cardid);
            out.write(password);
        }
        
        
        
        
        
        //连接数据库
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn=DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:orcl",
                "test0816","123456");
        PreparedStatement ps=conn.prepareStatement(
                "select * from t_bankcard where cardid=?" 
                        +"and password=? and state='1'");
        ps.setString(1,cardid);
        ps.setString(2,password);
        
        ResultSet rs=ps.executeQuery();
        
        if(rs.next())
        {
            out.write("用户名和密码正确");
        }
        else
        {
            out.write("用户名或密码错误");
        }
        //释放资源
        rs.close();
        ps.close();
        conn.close();
    %>
    
    </body>
    </html>

    Login.jsp

    <%@ 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>
    
    
    <form action="check2.jsp" method="post"><!--action里面写要转的jsp页面  -->
    卡号:<input type="text" name="cardid"><br>
    密码:<input type="password" name="password"><br>
    <input type="submit" value="登陆"><br>
    
    
    </form>
    
    </body>
    </html>

    CardDAO.java  建在java Resources src 包下面

    package com.hanqi.web;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    
    public class CardDAO {
        
        private ComboPooledDataSource cpds=new ComboPooledDataSource("helloc3p0");
        //通过配置文件构建连接池对象
        public boolean checkLogin(String cardid,String password)
        {
            boolean rtn=false;
            
            try {
                Connection conn=cpds.getConnection();
                
                PreparedStatement ps=conn.prepareStatement(
                        "select * from t_bankcard where cardid=?" 
                                +"and password=? and state='1'");
                ps.setString(1,cardid);
                ps.setString(2,password);
                
                ResultSet rs=ps.executeQuery();
                
                rtn=rs.next();//
                
            } catch (SQLException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }    
            
            return rtn;
        }
        
    }

    check2.jsp  webContent

    <%@page import="com.hanqi.web.CardDAO"%>
    <%@ 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 cardid=request.getParameter("cardid");
    String password=request.getParameter("password");
    
    if(cardid==null||password==null
    ||cardid.equals("")||password.equals(""))
    {
        out.write("请正确登陆");
    }
    else
    {
    //检查登陆信息
    CardDAO cd=new CardDAO();
    
    if(cd.checkLogin(cardid,password))
    {
        out.write("登陆成功");
    }
    else
    {
        out.write("登陆失败");
    }
        
        
        
    }
    
    %>
    </body>
    </html>
  • 相关阅读:
    CEIWEI CommTone串口调试精灵7.1 串口调试 串口工具
    CEIWEI USBMonitor USB监控精灵 v2.3.2 USB过滤驱动 USB监控
    CommMonitor8.0 串口过滤驱动 SDK DLL版本 C#/Delphi调用DEMO
    CommMonitor10.0.3串口过滤工具(serial port monitor)
    (1)、JEasyUI 之 Datagrid的Combobox 显示 textField 值的问题
    button 使用 flex 布局的兼容性问题
    探索 Reflect.apply 与 Function.prototype.apply 的区别
    awk 输出前 N 列的最简单方法
    在 Ubuntu 18.04 下安装 fcitx 及搜狗拼音输入法
    禁用 Gnome Shell 默认的 Ubuntu Dock 和 Ubuntu AppIndicators 扩展
  • 原文地址:https://www.cnblogs.com/hanruyue/p/6010545.html
Copyright © 2020-2023  润新知