Bootstrap

<%--
  Created by IntelliJ IDEA.
  User: 47
  Date: 2020/10/9
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户登录</title>
    <link  rel="stylesheet" href="css/bootstrap.css">

    <script src="js/bootstrap.bundle.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/jquery.min.js"></script>
   <style>
       .container
       {
     
         width: 28%;
           height: 20%;
           margin-top: 10%;

       }
   </style>


</head>

<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <form role="form" method="post" action="index.jsp">
                <h3 style="text-align: center">登录</h3>
                <div class="form-group">
                    <label for="exampleInputEmail1">用户名</label><input  type="text"  name="username"  class="form-control" id="exampleInputEmail1" type="email" />
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码</label><input type="password" name="password"    class="form-control" id="exampleInputPassword1" type="password" />
                </div>

                <button class="btn btn-default" type="submit">登录</button>
            </form>
        </div>
    </div>
</div>


</body>
</html>

Bootstrap_第1张图片

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 47
  Date: 2020/10/2
  Time: 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
  String username = request.getParameter("username");
  String password = request.getParameter("password");

    //加载驱动
    Class.forName("com.mysql.jdbc.Driver");

  String url = "jdbc:mysql://127.0.0.1:3306/book";
  Connection connection = DriverManager.getConnection(url,"root","root");



  //建立连接
  String sql = "select * from user where username = ? and password = ?";

  //建立  PreparedStatement 对象
  PreparedStatement ps = connection.prepareStatement(sql);

  ps.setString(1,username);
  ps.setString(2,password);


  ResultSet rs = ps.executeQuery();


  if(rs.next())
  {
     
    session.setAttribute("username",username);
    out.print("登录成功");
    response.sendRedirect("home.jsp");
  }
  else
  {
     
    out.print("登录失败");
    response.setHeader("refresh","3;url='login.jsp'");

  }


%>
<%@ page import="java.sql.*" %><%--

  Created by IntelliJ IDEA.

  User: 113主机

  Date: 2020/10/6

  Time: 14:10

  To change this template use File | Settings | File Templates.

--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

    <title>个人中心</title>

</head>

<body>

<%
   if(session.getAttribute("username")==null){
     
       out.print("你尚未登录3秒后跳转登录页面");
       response.setHeader("refresh","3;url=login.jsp");
   }else{
     
       out.print("欢迎来到个人主页!
"
); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/book"; Connection connection = DriverManager.getConnection(url,"root","root"); String sql = "select * from user"; PreparedStatement ps = connection.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()){ out.print(rs.getString("username")+"-"+rs.getString(3)+"
"
); } } %> </body> </html>

Bootstrap_第2张图片

你可能感兴趣的:(java,数据库,java)