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()<