登录
<%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 13:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录</title>
</head>
<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: 15%;
height: 15%;
margin-top: 100px;
}
</style>
<body background="1.jpg">
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<form role="form" action="RunLogON.jsp">
<div class="form-group">
<label for="exampleInputEmail1">用户名:</label><input type="text" class="form-control" id="exampleInputEmail1" name="username" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">密码:</label><input type="password" class="form-control" id="exampleInputPassword1" name="password"/>
</div>
<div class="checkbox">
</div> <button type="submit" class="btn btn-default">登录</button>
</form>
</div>
</div>
</div>
</body>
</html>
判断登录
<%@ 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: 吧
Date: 2020/12/1
Time: 14:02
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>判断登录</title>
</head>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="select * from users where uname=? and upass=?";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setString(1,username);
pstm.setString(2,password);
ResultSet rs=pstm.executeQuery();
if(rs.next())
{
session.setAttribute("username",username);
response.sendRedirect("SelectNews.jsp");
}
else {
out.print("<h2>账号或密码错误,3秒后返回登录页面</h2>");
response.setHeader("refresh","3,url=LogOn.jsp");
}
%>
<body>
</body>
</html>
查看教师信息
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>查看教师信息</title>
</head>
<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>
.row
{
width: 80%;
}
</style>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="select * from teacher ";
PreparedStatement pstm=connection.prepareStatement(sql);
ResultSet rs=pstm.executeQuery();
if(session.getAttribute("username")!=null)
{
}
else
{
response.sendRedirect("LogOn.jsp");
}
%>
<body background="5.jpg">
<div align="center">
<div class="row clearfix">
<div class="col-md-12 column" align="center">
<div align="right"><form action="SelectNewsById.jsp"><input type="text" value="按编号查找教师信息" name="id"><input type="submit" value="查找"></form></div>
<h2 align="center">欢迎登陆!</h2>
<div align="left"> <a href="InsertNews.jsp" style="text-decoration: none; color:black;" ><font size="5">插入</font></a></div>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>
编号
</th>
<th>
姓名
</th>
<th>
年龄
</th>
<th>
性别
</th>
<th>
电话
</th>
<th>
邮箱
</th>
<th>
地址
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<%
while( rs.next())
{
out.print("<tr>");
out.print(
"<td>"+rs.getString("id")+
"</td><td>"+rs.getString("name")+
"</td><td>"+rs.getInt("age")+
"</td><td>"+rs.getInt("sex")+
"</td><td>"+rs.getString("tel")+
"</td><td>"+rs.getString("email")+
"</td><td>"+rs.getString("address")+
"</td><td COLSPAN=2><a href='DeleteNews.jsp?id="+rs.getString("id")+"'>删除</a>"
+" <a href='UpdateNews.jsp?id="+rs.getString("id")+"'>修改</a>"+"</td>");
out.print("</tr>");
}%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
用id查找信息
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 16:21
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>按编号查找教师信息</title>
</head>
<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>
.col-md-12
{
margin-top: 100px;
}
</style>
<%
int id=Integer.parseInt(request.getParameter("id"));
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="select * from teacher where id=?";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setInt(1,id);
ResultSet rs=pstm.executeQuery();
if(session.getAttribute("username")!=null)
{
}
else
{
response.sendRedirect("LogOn.jsp");
}
%>
<body background="5.jpg">
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div align="right"><form action="SelectNewsById.jsp"><input type="text" value="按编号查找教师信息"><input type="submit" value="查找"></form></div>
<h2 align="center">欢迎登陆!</h2>
<div > <a href="InsertNews.jsp" style="text-decoration: none; color:black;" ><font size="5">插入</font></a> <a href="SelectNews.jsp">返回教师信息页面</a></div>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>
编号
</th>
<th>
姓名
</th>
<th>
年龄
</th>
<th>
性别
</th>
<th>
电话
</th>
<th>
邮箱
</th>
<th>
地址
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<%
while( rs.next())
{
out.print("<tr>");
out.print(
"<td>"+rs.getString("id")+
"</td><td>"+rs.getString("name")+
"</td><td>"+rs.getInt("age")+
"</td><td>"+rs.getInt("sex")+
"</td><td>"+rs.getString("tel")+
"</td><td>"+rs.getString("email")+
"</td><td>"+rs.getString("address")+
"</td><td COLSPAN=2><a href='DeleteNews.jsp?id="+rs.getString("id")+"'>删除</a>"
+" <a href='UpdateNews.jsp?id="+rs.getString("id")+"'>修改</a>"+"</td>");
out.print("</tr>");
}%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
修改信息
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改教师信息</title>
</head><link rel="stylesheet" href="css/bootstrap.css"><script src="js/jquery.min.js"></script>
<script src="js/bootstrap.bundle.js"></script>
<script src="js/bootstrap.js"></script>
<style>
.table{
margin-left: -15%;
}
</style>
<body background="5.jpg">
<form action="UpdateNews2.jsp" method="get">
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="select * from teacher where id=?";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setInt(1,Integer.parseInt(request.getParameter("id")));
ResultSet rs=pstm.executeQuery();
session.setAttribute("ID",request.getParameter("id"));
%>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column" align="center">
<h2 align="center">修改用户!</h2>
<div align="left" ><a href="SelectNews.jsp"><font size="+2">返回教师信息页面</font></a></div>
<table class="table table-hover table-striped" >
<thead>
<tr>
<th></th>
<th >
编号
</th>
<th>
姓名
</th>
<th>
年龄
</th>
<th>
性别
</th>
<th>
电话
</th>
<th>
邮箱
</th>
<th>
地址
</th>
</tr>
</thead>
<tbody>
<%
while( rs.next())
{
out.print("<tr>");
out.print( "<td>"+"原信息"+
"</td><td>"+rs.getString("id")+
"</td><td>"+rs.getString("name")+
"</td><td>"+rs.getInt("age")+
"</td><td>"+rs.getInt("sex")+
"</td><td>"+rs.getString("tel")+
"</td><td>"+rs.getString("email")+
"</td><td>"+rs.getString("address")+
"</td>");
out.print("</tr>");
}%>
<tr>
<td>修改信息</td>
<td><input type="text" name="UpdateId" ></td>
<td><input type="text" name="UpdateserName"></td>
<td><input type="text" name="UpdateAge"></td>
<td><input type="text" name="UpdateSex" ></td>
<td><input type="text" name="UpdateserTel"></td>
<td><input type="text" name="UpdateEmail"></td>
<td><input type="text" name="UpdateAddress"></td>
</tr>
<tr><td colspan="8" style="text-align: center;"><input type="submit" value="提交"></td></tr>
</tbody>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
判断修改
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:28
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改教师信息</title>
</head>
<body>
</body>
<%
int ses=Integer.parseInt(session.getAttribute("ID").toString());
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="update teacher set id=?, name=?, age=?,sex=?,tel=?,email=?,address=? where id=?";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setInt(1,Integer.parseInt(request.getParameter("UpdateId")));
pstm.setString(2,request.getParameter("UpdateserName"));
pstm.setInt(3,Integer.parseInt(request.getParameter("UpdateAge")));
pstm.setInt(4,Integer.parseInt(request.getParameter("UpdateSex")));
pstm.setString(5,request.getParameter("UpdateserTel"));
pstm.setString(6,request.getParameter("UpdateEmail"));
pstm.setString(7,request.getParameter("UpdateAddress"));
pstm.setInt(8,ses);
int count=pstm.executeUpdate();
if(count>0)
{
out.print("<h2>操作成功,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
else
{
out.print("<h2>操作失败,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
%>
</html>
插入页面
<%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:18
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>插入教师信息</title>
</head>
<%
if(session.getAttribute("username")!=null)
{
}
else
{
response.sendRedirect("look.jsp");
}
%>
<link rel="stylesheet" href="css/bootstrap.css"><script src="js/jquery.min.js"></script>
<script src="js/bootstrap.bundle.js"></script>
<script src="js/bootstrap.js"></script>
<body background="5.jpg">
<form action="InsertNews2.jsp" method="get">
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<h2 align="center">插入用户!</h2>
<table class="table table-hover table-striped" style="margin-left: -15%">
<thead>
<tr>
<th></th>
<th>编号</th>
<th>
姓名
</th>
<th>
年龄
</th>
<th>
性别
</th>
<th>
电话
</th>
<th>
邮箱
</th>
<th>
地址
</th>
</tr>
</thead>
<tbody>
<tr>
<td>修改信息</td>
<td><input type="text" name="InsertId" ></td>
<td><input type="text" name="InsertName" ></td>
<td><input type="text" name="InsertAge"></td>
<td><input type="text" name="InsertSex"></td>
<td><input type="text" name="InsertTel" ></td>
<td><input type="text" name="InsertEmail"></td>
<td><input type="text" name="InsertAddress"></td>
</tr>
<tr><td colspan="8" style="text-align: center;"><input type="submit" value="提交"></td></tr>
</tbody>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
插入判断
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:38
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>插入教师信息</title>
</head>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="insert teacher values(?,?,?,?,?,?,?)";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setInt(1,Integer.parseInt(request.getParameter("InsertId")));
pstm.setString(2,request.getParameter("InsertName"));
pstm.setInt(3,Integer.parseInt(request.getParameter("InsertAge")));
pstm.setInt(4,Integer.parseInt(request.getParameter("InsertSex")));
pstm.setString(5,request.getParameter("InsertTel"));
pstm.setString(6,request.getParameter("InsertEmail"));
pstm.setString(7,request.getParameter("InsertAddress"));
int count=pstm.executeUpdate();
if (count>0)
{
out.print("<h2>操作成功,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
else
{
out.print("<h2>操作失败,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
%>
</html>
删除页面
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %><%--
Created by IntelliJ IDEA.
User: 吧
Date: 2020/12/1
Time: 14:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>删除教师信息</title>
</head>
<body>
</body>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/lixiuying";
Connection connection= DriverManager.getConnection(url,"root","root");
String sql="delete from teacher where id=?";
PreparedStatement pstm=connection.prepareStatement(sql);
pstm.setInt(1,Integer.parseInt(request.getParameter("id")));
int count=pstm.executeUpdate();
if(count>0)
{
out.print("<h2>操作成功,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
else
{
out.print("<h2>操作失败,即将返回教师信息页面</h2>");
response.setHeader("refresh","3,url=SelectNews.jsp");
}
%>
</html>