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

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

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

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

首页:

http://localhost:8080/login.jsp

登录:

admin 123456

功能:

司机管理、汽车管理、违章管理


@WebServlet("/selectBusById")
public class SelectBusByIdServlet extends HttpServlet {

    BusService busService = new BusService();

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

        String licensePlate = request.getParameter("licensePlate");
//        if (licensePlate != null) {
//            licensePlate = new String(licensePlate.getBytes("ISO-8859-1"), "UTF-8");
//        }
        System.out.println("根据车牌号查车:" + licensePlate);
        // 调用 BusService 的按车牌号查询方法
        List<Bus> allBuses = busService.getAllBuses();
        for (Bus bus : allBuses) {
            if (bus.getLicensePlate().equalsIgnoreCase(licensePlate)) {
                // 将查询结果传递给前端
                request.setAttribute("bus", bus);
                request.getRequestDispatcher("BusUpdate.jsp").forward(request, response);
            }
        }
        throw new RuntimeException("根据车牌号查车:" + licensePlate + ",示找到对应的车");
    }

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

    BusService busService = new BusService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现
    }

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

        String endTime = endDate.concat(" ").concat(endtime.concat(":00"));
        System.out.println(startTime+" "+endTime);

        // 调用 DriverService 中的查询方法
        List<ViolationRecord> violationRecords = vioService.selectByConViolationRecords(employeeId,startTime,endTime);

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

    }

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

}
@WebServlet("/addViolationRecord")
public class AddViolationRecordServlet extends HttpServlet {

    ViolationRecordService violationRecordService = new ViolationRecordService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现

    }

}
@WebServlet("/addViolationRecord")
public class AddViolationRecordServlet extends HttpServlet {

    ViolationRecordService violationRecordService = new ViolationRecordService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现

    }

    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("/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);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

@WebServlet("/selectAllDrivers")
public class SelectAllDriversServlet extends HttpServlet {

    DriverService driverService = new DriverService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
         request.setCharacterEncoding("UTF-8");
        List<Driver> drivers = driverService.getAllDrivers();
        // 将查询结果传递给前端,这里可以使用 request.setAttribute() 然后转发到对应的 JSP 页面
        request.setAttribute("drivers",drivers);

        request.getRequestDispatcher("/mydemo.jsp").forward(request,response);
        request.setAttribute("selectedModule", "driverInfo");
        response.getWriter().println("Drivers: " + drivers);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
@WebServlet("/selectAllBus")
public class SelectAllBusServlet extends HttpServlet {

    }

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

@WebServlet("/addDriver")
public class AddDriverServlet extends HttpServlet {

    private final DriverService driverService = new DriverService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取前端传递的参数,根据具体情况来获取并封装 Driver 对象
        request.setCharacterEncoding("UTF-8");
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        int employeeId = Integer.parseInt(request.getParameter("employeeId"));
        int age = Integer.parseInt(request.getParameter("age"));
        String nativePlace = request.getParameter("nativePlace");
        String enDate = request.getParameter("entryDate");

    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);
        }
    }

    @Override
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String starttime = request.getParameter("starttime");
        String endtime = request.getParameter("endtime");

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

        String endTime = endDate.concat(" ").concat(endtime.concat(":00"));
        System.out.println(startTime+" "+endTime);

        // 调用 DriverService 中的查询方法
        List<ViolationRecord> violationRecords = vioService.selectByConViolationRecords(employeeId,startTime,endTime);

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

    }

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

}
                request.getRequestDispatcher("BusUpdate.jsp").forward(request, response);
            }
        }
        throw new RuntimeException("根据车牌号查车:" + licensePlate + ",示找到对应的车");
    }

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

    BusService busService = new BusService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现
    }

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

        String licensePlate = request.getParameter("licensePlate");
        int totalSeats = Integer.parseInt(request.getParameter("totalSeats"));
        String brand = request.getParameter("brand");
        int age = Integer.parseInt(request.getParameter("age"));

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

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


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

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

@WebServlet("/selectBusById")
public class SelectBusByIdServlet extends HttpServlet {

    BusService busService = new BusService();

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

        String licensePlate = request.getParameter("licensePlate");
//        if (licensePlate != null) {
//            licensePlate = new String(licensePlate.getBytes("ISO-8859-1"), "UTF-8");
//        }
        System.out.println("根据车牌号查车:" + licensePlate);
        // 调用 BusService 的按车牌号查询方法
        List<Bus> allBuses = busService.getAllBuses();
        for (Bus bus : allBuses) {
            if (bus.getLicensePlate().equalsIgnoreCase(licensePlate)) {
                // 将查询结果传递给前端
                request.setAttribute("bus", bus);
                request.getRequestDispatcher("BusUpdate.jsp").forward(request, response);
            }
        }
        throw new RuntimeException("根据车牌号查车:" + licensePlate + ",示找到对应的车");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 在 doPost 中调用 doGet
        doGet(request, response);
    }
}
        request.setAttribute("selectedModule", "driverInfo");
        response.getWriter().println("Drivers: " + drivers);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
@WebServlet("/selectAllBus")
public class SelectAllBusServlet extends HttpServlet {

    BusService busService = new BusService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");

        // 使用 BusService 获取所有公交车信息
        List<Bus> buses = busService.getAllBuses();

        // 将查询结果传递给前端,这里可以使用 request.setAttribute() 然后转发到对应的 JSP 页面
        request.setAttribute("buses", buses);
        request.setAttribute("selectedModule", "carInfo");
        // 转发到 JSP 页面
        request.getRequestDispatcher("/mydemo.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

@WebServlet("/addDriver")
public class AddDriverServlet extends HttpServlet {

    private final DriverService driverService = new DriverService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 实际的业务逻辑在 doPost 中实现

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取前端传递的参数,根据具体情况来获取并封装 Driver 对象
        request.setCharacterEncoding("UTF-8");
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        int employeeId = Integer.parseInt(request.getParameter("employeeId"));
        int age = Integer.parseInt(request.getParameter("age"));
        String nativePlace = request.getParameter("nativePlace");
        String enDate = request.getParameter("entryDate");
        String contactNumber = request.getParameter("contactNumber");
        String idCardNumber = request.getParameter("idCardNumber");
        String position = request.getParameter("position");
        Date entryDate = null;
        // Convert entryDate String to Date
//        try {
//
//            entryDate = dateFormat.parse(enDate);
            Driver driver = new Driver(employeeId, name, gender, age, nativePlace, enDate, contactNumber, idCardNumber, position);
            // 调用 DriverService 的更新方法
            driverService.addDriver(driver);

            request.getRequestDispatcher("/selectAllDrivers").forward(request,response);

//
//        } catch (ParseException e) {
//            throw new RuntimeException(e);
//        }
        // Call the DriverService to add the new driver to the database

    }
}
        String idCardNumber = request.getParameter("idCardNumber");
        String position = request.getParameter("position");
        Date entryDate = null;
        // Convert entryDate String to Date
//        try {
//
//            entryDate = dateFormat.parse(enDate);
            Driver driver = new Driver(employeeId, name, gender, age, nativePlace, enDate, contactNumber, idCardNumber, position);
            // 调用 DriverService 的更新方法
            driverService.addDriver(driver);

            request.getRequestDispatcher("/selectAllDrivers").forward(request,response);

//
//        } catch (ParseException e) {
//            throw new RuntimeException(e);
//        }
        // Call the DriverService to add the new driver to the database

    }
}

@WebServlet("/selectByConViolation")
public class SelectByConViolation extends HttpServlet {

    ViolationRecordService vioService = new ViolationRecordService();
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 从前端获取查询条件(这里假设前端通过 GET 请求传递了 team 和 gender 参数)
        int employeeId = Integer.parseInt(request.getParameter("employeeId"));
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String starttime = request.getParameter("starttime");
        String endtime = request.getParameter("endtime");

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

@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);
    }
}

@WebServlet("/updateBus")
public class UpdateBusServlet extends HttpServlet {

    BusService busService = new BusService();

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

        String licensePlate = request.getParameter("licensePlate");
        int totalSeats = Integer.parseInt(request.getParameter("totalSeats"));
        String brand = request.getParameter("brand");
        int age = Integer.parseInt(request.getParameter("age"));
//        if (licensePlate != null) {
//            licensePlate = new String(licensePlate.getBytes("ISO-8859-1"), "UTF-8");
//        }
        System.out.println(licensePlate);
        System.out.println(totalSeats);
        // 创建 Bus 对象
        Bus bus = new Bus(licensePlate, totalSeats, brand, age);
        // 调用 BusService 的更新方法
        busService.updateBus(bus);

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

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

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取前端传递的参数,根据具体情况来获取
        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();
        violationRecord.setViolationNumber(violationNumber);
        violationRecord.setEmployeeId(employeeId);
        violationRecord.setViolationName(violationName);
        violationRecord.setViolationTime(violationTime);
        violationRecord.setViolationLocation(violationLocation);
        violationRecord.setLicensePlate(licensePlate);
        violationRecord.setRecorder(recorder);

        // 调用 ViolationRecordService 的更新方法
        violationRecordService.updateViolationRecord(violationRecord);

        // 重定向到查询全部违章记录的 Servlet
        request.getRequestDispatcher("/selectAllViolations").forward(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取前端传递的参数,根据具体情况来获取并封装 ViolationRecord 对象
        this.doGet(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);
    }
}

@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);

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值