zoukankan      html  css  js  c++  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">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="zjxcsb.jsp" method="post">
    用户名:<input type="text" name = "username"><br>
    密码:<input type="password" name="pass"><br>
    <input type="submit" value="登录">
    </form>
    </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>Insert title here</title>
    </head>
    <body>
    <%
    String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName = test";
    String userName="sa";
    String userPwd="123456";

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

    %>
    </body>
    </html>

  • 相关阅读:
    pip 安装
    「csp模拟」模拟测试15
    某些博客的优化
    晚间测试6
    「csp模拟」模拟测试15
    「csp模拟」模拟测试14
    线段树维护单调栈
    晚间测试 2
    晚间测试 1
    晚间测试4
  • 原文地址:https://www.cnblogs.com/ylx111/p/6446112.html
Copyright © 2011-2022 走看看