基于javaweb的JSP+Servlet简单教师信息管理系统(java+jsp+servlet+mysql+jdbc)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

302223352507

312223352507

基于javaweb的JSP+Servlet简单教师信息管理系统(java+jsp+servlet+mysql+jdbc)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    <br>
<div id="submit">
<tr>
<button type="submit" onclick="return checkForm()">添加</button>
<button type="reset">重置</button>

</tr>
</div>
</form>

<script type="text/javascript">
function checkForm() {
var id = addForm.id.value;
var name = addForm.name.value;
var salary = addForm.salary.value;

// 教职工号和姓名不能为空
if (id == "" || id == null) {
alert("请输入教职工号");
addForm.id.focus();
return false;
} else if (name == "" || name == null) {
alert("请输入教师姓名");
addForm.name.focus();
return false;
}
else if (salary == "" || salary == null) {
alert("请输入教工资");
addForm.salary.focus();
return false;
}
return true;
}
</script>

<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>
<%@ page import="com.sjsq.vo.Teacher" %>
<%@ page import="com.sjsq.service.TeacherService" %>
<%@ page import="com.sjsq.service.impl.TeacherServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>新增教师</title>
</head>
<body>
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding("UTF-8");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Override
public String toString() {
return "Admin{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
package com.sjsq.service.impl;

/**
* @description:
*/
public class AdminServiceImpl implements AdminService{

private AdminDao adminDao = new AdminDaoImpl();

public Admin login(Admin admin) {
return adminDao.login(admin);
}
}
package com.sjsq.service;


/**
* @description: 管理员服务层接口
*/
public interface AdminService {

/**
* 用户登录
* @param admin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 */
public static void close(Connection con, PreparedStatement ps, ResultSet rs) {
// 关闭资源,避免出现异常
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

/**
* 设置增删改的方法
*
* @param sql
* @param arr
* @return
*/
public static boolean addUpdateDelete(String sql, Object[] arr) {
Connection con = null;
PreparedStatement ps = null;
try {
// 第一步:连接数据库
con = DBUtil.getConnection();
// 第二步:预编译
ps = con.prepareStatement(sql);
// 第三步:设置值
if (arr != null && arr.length != 0) {
for (int i = 0; i < arr.length; i++) {
ps.setObject(i + 1, arr[i]);
}
}
int count = ps.executeUpdate();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    <div id="submit">
<tr>
<button type="submit" onclick="return checkForm()">添加</button>
<button type="reset">重置</button>

</tr>
</div>
</form>

<script type="text/javascript">
function checkForm() {
var id = addForm.id.value;
var name = addForm.name.value;
var salary = addForm.salary.value;

// 教职工号和姓名不能为空
if (id == "" || id == null) {
alert("请输入教职工号");
addForm.id.focus();
return false;
} else if (name == "" || name == null) {
alert("请输入教师姓名");
addForm.name.focus();
return false;
}
else if (salary == "" || salary == null) {
alert("请输入教工资");
addForm.salary.focus();
return false;
}
return true;
}
</script>

<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>
<%@ page import="com.sjsq.vo.Teacher" %>
<%@ page import="com.sjsq.service.TeacherService" %>
<%@ page import="com.sjsq.service.impl.TeacherServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * @description: 登录系统实现
*/
public class AdminDaoImpl implements AdminDao {

/**
* 登录系统
* @param admin
* @return
*/
@Override
public Admin login(Admin admin) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.获取数据库连接
con = DBUtil.getConnection();
// 2.写sql
String sql = "select * from admin where username = ? and password = ?";
// 3.预编译
ps = con.prepareStatement(sql);
// 4.设置值
ps.setObject(1, admin.getUsername());
ps.setObject(2, admin.getPassword());
rs = ps.executeQuery();
Admin adminLogin = null;
if (rs.next()) {
adminLogin = new Admin();
// 从数据库中获取值到实体类的setter方法中
adminLogin.setUsername(rs.getString("username"));
adminLogin.setPassword(rs.getString("password"));

// 返回的是你查询出来的完整的对象
return adminLogin;

}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Override
public String toString() {
return "Admin{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
package com.sjsq.service.impl;

/**
* @description:
*/
public class AdminServiceImpl implements AdminService{

private AdminDao adminDao = new AdminDaoImpl();

public Admin login(Admin admin) {
return adminDao.login(admin);
}
}
package com.sjsq.service;


/**
* @description: 管理员服务层接口
*/
public interface AdminService {


项目链接:
https://javayms.github.io?id=342223402507201br
https://javayms.pages.dev?id=342223402507201br