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>

  • 相关阅读:
    一、
    【2019-11-25】美好需要主动去发现
    《软件方法(上)》读书笔记
    【2019-11-24】读书让人美丽
    【2019-11-23】让别人来管理自己
    【2019-11-22】不聪明只有靠笨方法了
    【2019-11-21】要像人一样思考
    【2019-11-20】作为丈夫的反省
    【2019-11-19】基础科学的意义发现
    【2019-11-18】重新审视一下自己的思维
  • 原文地址:https://www.cnblogs.com/ylx111/p/6446112.html
Copyright © 2011-2022 走看看