• java登陆


    登陆

    <%@ 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">
    <script type="text/javascript">
        function $(id) {
            return document.getElementById(id);
        }
        
        function check() {
            var user = $("user").value;
            var pwd = $("pwd").value;
            
            $("userInfo").innerHTML="";
            $("pwdInfo").innerHTML="";
            
            if(user == "") {
                $("userInfo").innerHTML="用户名不能为空!";
                $("user").focus();
                return false;
            }
            
            if(pwd == "") {
                $("pwdInfo").innerHTML="密码不能为空!";
                $("pwd").focus();
                return false;
            }
            
            return true;
        }
    </script>
    
    <style type="text/css">
        #userInfo{color:red;}
        #pwdInfo{color:red;}
    </style>
    
    <title>登录</title>
    
    </head>
    
    <body>
        <center>
            <form action="loginResult.jsp" method="post" onsubmit="return check()">
                <br><br><br><br><br><br>
                <table>
                    <tr><td>用户名:</td><td><input type="text" name="userName" id="user"><span id="userInfo" ></span></td></tr>
                    <tr><td>密码:</td><td><input type="password" name="userPwd" id="pwd"><span id="pwdInfo"></span></td></tr>
                    <tr><td></td><td><input type="submit" value="登     录"></td>
                    
                </table>
            </form>
        </center>
    </body>
    
    </html>

    登陆判断

    <%@ page language="java" import="java.sql.*" 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>登录结果</title>
    </head>
    <body>
        <%
            Connection conn = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            String driverName = "com.mysql.jdbc.Driver";
            String userName = "root";
            String userPwd = "123";
            String dbName = "hkz";
            String url1 = "jdbc:mysql://localhost:3306/" + dbName;
            String url2 = "?user=" + userName + "&password=" + userPwd;
            String url3 = "&useUnicode=true&characterEncoding=UTF-8";
            String url = url1 + url2 + url3;
            request.setCharacterEncoding("UTF-8");
            Class.forName(driverName);
            conn = DriverManager.getConnection(url);
            String sql = "select * from userinfo where user=?";
            pstmt = conn.prepareStatement(sql);
            String user = request.getParameter("userName");
            String password = request.getParameter("userPwd");
            pstmt.setString(1, user);
            rs = pstmt.executeQuery();
            if(rs.next()) {
                sql = "select * from userinfo where user=? and pwd=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, user);
                pstmt.setString(2, password);
                rs = pstmt.executeQuery();
                if(rs.next()) {
                    %><center><h1>用户 <%=rs.getString("user")%>登陆成功!</h1></center><%
                    
                }
                else {
                    %><center><h1>密码错误!</h1></center><%
                }
            }    
            else {
                %><center><h1>用户名不存在!</h1></center>
            <%}
            if(rs != null) {
                rs.close();
            }
            if(pstmt != null) {
                pstmt.close();
            }
            if(conn != null) {
                conn.close();
            }
        %>
    </body>
    </html>

    连接数据库

  • 相关阅读:
    C#的委托
    解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题
    【WPF学习】第三十六章 样式基础
    asp.net core 3.x 身份验证-3cookie身份验证原理
    C#设计模式学习笔记:(9)组合模式
    Asp.net Core MVC(三)UseMvc设置路由
    C#后台异步消息队列实现
    ASP.NET CORE 内置的IOC解读及使用
    VS2015发布WEB项目
    C#的冒泡排序
  • 原文地址:https://www.cnblogs.com/clueless/p/6440369.html
Copyright © 2020-2023  润新知