zoukankan      html  css  js  c++  java
  • 软件工程概论—用户登录界面

    1、程序所需的代码:

        1)<%@ 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>
            <center>
            <form action="loginResult.jsp" method="post" >
            <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>

        2)  Connection conn = null;
              PreparedStatement pstmt = null;
              ResultSet rs = null;
              String driverName = "com.mysql.jdbc.Driver";
              String userName = "root";
              String userPwd = "196521";
              String dbName = "test2";
              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 username=?";
              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 username=? and password=?";
                    pstmt = conn.prepareStatement(sql);
                    pstmt.setString(1, user);
                    pstmt.setString(2, password);
                    rs = pstmt.executeQuery();
                     if(rs.next()) {
                             %><center><h1>用户 <%=rs.getString("username")%>登陆成功!</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();
        }
        %>

    2、相应的截图:

    1)2)

    3)

  • 相关阅读:
    axis2 WebService 请求参数xml格式
    钉钉扫码登录第三方,appSecret签名算法(附包名)
    win10 IE浏览器中,设置指定程序查看源文件,设置查看源默认程序
    myeclipse CI 2018.8.0和 myeclipse 10 禁止空格自动上屏,自动补全插件
    开发必备网站记录
    二叉树的前序中序后序遍历(简洁)
    贪心算法入门
    Java-二分查找与二叉树关系详解-2021-7-20
    Visual Studio Code快速创建模板(html等)
    java 面向对象1之继承
  • 原文地址:https://www.cnblogs.com/th1314/p/6444932.html
Copyright © 2011-2022 走看看