数据库操作2020.10.29

201819102037 尹凤波

1.登陆页面
首先创建登录页面login.jsp,再利用 js css 使登录页面美化
主要代码如下:

<title>登录页面</title>

<link rel="stylesheet" href="css/bootstrap.css">

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.bundle.js"></script>

<style>
    .container{
   
        width: 20%;
        height: 20%;
        margin-top: 10%;
    }
</style>
<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" />
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码:</label><input type="password" name="password" class="form-control" id="exampleInputPassword1" />
                </div>
                <button type="submit" style="width: 100%" class="btn btn-info">提交</button>
            </form>
        </div>
    </div>
</div>
</body>

在这里插入图片描述
登录跳转页面,登陆时录入无效数据登录失败会跳转到登陆页面,登陆成功会跳转到个人管理页面

<%
  //修改request中的数据编码
  request.setCharacterEncoding("utf-8");
  String username = request.getParameter("username");
  String password = request.getParameter("password");

  //加载数据库驱动
  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 where username = ? and password = ?";
  //使用PreparedStatement对象执行sql语句
  PreparedStatement ps = connection.prepareStatement(sql);

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

  ResultSet rs = ps.executeQuery()<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值