zoukankan      html  css  js  c++  java
  • 登录界面

    连接数据库
    import java.sql.*;

    public class Main {
    public static void main(String [] args)
    {
    String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=qwer";
    String userName="sa";
    String userPwd="829727";
    try
    {
    Class.forName(driverName);
    System.out.println("加载驱动成功!");
    }catch(Exception e){
    e.printStackTrace();
    System.out.println("加载驱动失败!");
    }
    try{
    Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
    System.out.println("连接数据库成功!");
    }catch(Exception e)
    {
    e.printStackTrace();
    System.out.print("SQL Server连接失败!");
    }
    }
    }

    登录界面

    <%@ 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=ISO-8859-1">
    <title>登录界面</title>
    </head>
    <body >
    <center>
    <h2>登录界面</h2>
    <form action="lianjie.jsp" method="post">
    用户:<input type="text" name = "usern ame"><br>
    密码:<input type="password" name="password"><br>
    <input type="submit" value="提交">
    </form>
    </center>
    </body>
    </html>

    登录

    <%@ page language="java" import="java.sql.*" import="java.util.*" 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>
    <%
    String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=qwer";
    String userName="sa";
    String userPwd="829727";

    Class.forName(driverName);
    Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
    String sql = "select * from Table_1 where [name]=? and [password]=?";
    PreparedStatement pstmt = dbConn.prepareStatement(sql);
    request.setCharacterEncoding("UTF-8");
    String user = request.getParameter("username");
    String pass = request.getParameter("password");
    pstmt.setString(1, user);
    pstmt.setString(2, pass);
    ResultSet rs = pstmt.executeQuery();
    if(rs.next()) {
    %><center><h1>登陆成功!</h1></center><%
    }
    else
    {
    %><center><h1>登陆失败!</h1></center><%
    }

    %>
    </body>
    <ml>

  • 相关阅读:
    LeetCode 1245. Tree Diameter
    LeetCode 1152. Analyze User Website Visit Pattern
    LeetCode 1223. Dice Roll Simulation
    LeetCode 912. Sort an Array
    LeetCode 993. Cousins in Binary Tree
    LeetCode 1047. Remove All Adjacent Duplicates In String
    LeetCode 390. Elimination Game
    LeetCode 1209. Remove All Adjacent Duplicates in String II
    LeetCode 797. All Paths From Source to Target
    LeetCode 1029. Two City Scheduling
  • 原文地址:https://www.cnblogs.com/qq1499632156/p/6473267.html
Copyright © 2011-2022 走看看