基于javaweb的JSP+Servlet公交管理系统(java+servlet+jsp+mybaits+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

002024121401

012024121401

022024121401

032024121401

582024111401

592024111401

基于javaweb的JSP+Servlet公交管理系统(java+servlet+jsp+mybaits+mysql+tomcat)

首页:
http://localhost:8080/login.jsp

登录:
admin 123456

功能:
司机管理、汽车管理、违章管理

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
        String brand = request.getParameter("brand");
int age = Integer.parseInt(request.getParameter("age"));

Bus bus = new Bus(licensePlate, totalSeats, brand, age);

// 调用 BusService 的添加方法
busService.addBus(bus);

// 重定向到查询全部公交车信息的 Servlet,这里可能需要根据您的实际业务逻辑进行调整
request.getRequestDispatcher("/selectAllBus").forward(request,response);
}
}

@WebServlet("/deleteBus")
public class DeleteBusServlet extends HttpServlet {

BusService busService = new BusService();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
// request.setCharacterEncoding("GBK");
String licensePlate = request.getParameter("licensePlate");
// if (licensePlate != null) {
// licensePlate = new String(licensePlate.getBytes("ISO-8859-1"), "UTF-8");
// }
System.out.println(licensePlate);
// 调用 BusService 的删除方法
busService.deleteBus(licensePlate);

// 重定向到查询全部公交车信息的 Servlet,这里可能需要根据您的实际业务逻辑进行调整
request.getRequestDispatcher("/selectAllBus").forward(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
this.doGet(request, response);
}
}

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
    }

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取并封装 ViolationRecord 对象
request.setCharacterEncoding("UTF-8");

int violationNumber = Integer.parseInt(request.getParameter("violationNumber"));
int employeeId = Integer.parseInt(request.getParameter("employeeId"));
String violationName = request.getParameter("violationName");
String violationTime = request.getParameter("violationTime");
String violationLocation = request.getParameter("violationLocation");
String licensePlate = request.getParameter("licensePlate");
String recorder = request.getParameter("recorder");

// 创建 ViolationRecord 对象
ViolationRecord violationRecord = new ViolationRecord(violationNumber, employeeId, violationName,
violationTime, violationLocation, licensePlate, recorder);

// 调用 ViolationRecordService 的添加方法
violationRecordService.addViolationRecord(violationRecord);

// 重定向到查询全部违章记录的 Servlet,这里可能需要根据您的实际业务逻辑进行调整
request.getRequestDispatcher("/selectAllViolations").forward(request,response);
}
}
@WebServlet("/selectByFleetViolation")
public class SelectByFleetViolationServelt extends HttpServlet{


ViolationFleetService fleetService = new ViolationFleetService();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
int fleetNumber = Integer.parseInt(request.getParameter("fleetnumber"));
String startDate = request.getParameter("startDate1");
String endDate = request.getParameter("endDate1");
String starttime = request.getParameter("starttime1");
String endtime = request.getParameter("endtime1");

String startTime = startDate.concat(" ").concat(starttime).concat(":00");


String endTime = endDate.concat(" ").concat(endtime.concat(":00"));
System.out.println(startTime+" "+endTime);
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
        int fleetnumber = Integer.parseInt(request.getParameter("fleetnumber"));


// 调用 DriverService 中的查询方法
List<Driver> drivers = driverService.selectByConDrivers(fleetnumber);

// 将查询结果传递到前端,这里使用 request.setAttribute(),你也可以选择其他方式
request.setAttribute("drivers",drivers);
request.getRequestDispatcher("/mydemo.jsp").forward(request,response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 在 doPost 中调用 doGet,实现代码的复用
this.doGet(request, response);
}


}



@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String username = request.getParameter("username");
String password = request.getParameter("password");
if ("admin".equals(username) && "123456".equals(password)) {
HttpSession session = request.getSession();
session.setAttribute("user", new user(username, password));
response.sendRedirect("/selectAllDrivers");
} else {
request.setAttribute("errormsg", "用户名或密码错误");
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
}

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
    BusService busService = new BusService();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
// request.setCharacterEncoding("GBK");
String licensePlate = request.getParameter("licensePlate");
// if (licensePlate != null) {
// licensePlate = new String(licensePlate.getBytes("ISO-8859-1"), "UTF-8");
// }
System.out.println(licensePlate);
// 调用 BusService 的删除方法
busService.deleteBus(licensePlate);

// 重定向到查询全部公交车信息的 Servlet,这里可能需要根据您的实际业务逻辑进行调整
request.getRequestDispatcher("/selectAllBus").forward(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
this.doGet(request, response);
}
}

@WebServlet("/selectViolationRecordById")
public class SelectViolationRecordByIdServlet extends HttpServlet {

ViolationRecordService violationRecordService = new ViolationRecordService();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
int violationNumber = Integer.parseInt(request.getParameter("violationNumber"));
System.out.println(violationNumber);
// 调用 ViolationRecordService 的按违章号查询方法
ViolationRecord violationRecord = violationRecordService.getViolationRecordById(violationNumber);

// 将查询结果传递给前端
request.setAttribute("violationRecord", violationRecord);
request.getRequestDispatcher("ViolationRecordUpdate.jsp").forward(request, response);
}

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
@WebServlet("/selectViolationRecordById")
public class SelectViolationRecordByIdServlet extends HttpServlet {

ViolationRecordService violationRecordService = new ViolationRecordService();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取前端传递的参数,根据具体情况来获取
int violationNumber = Integer.parseInt(request.getParameter("violationNumber"));
System.out.println(violationNumber);
// 调用 ViolationRecordService 的按违章号查询方法
ViolationRecord violationRecord = violationRecordService.getViolationRecordById(violationNumber);

// 将查询结果传递给前端
request.setAttribute("violationRecord", violationRecord);
request.getRequestDispatcher("ViolationRecordUpdate.jsp").forward(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 在 doPost 中调用 doGet
doGet(request, response);
}
}
@WebServlet("/selectAllViolations")
public class SelectAllViolationsServlet extends HttpServlet {

ViolationRecordService violationRecordService = new ViolationRecordService();

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {


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