@WebServlet("/admin/updateCourse") public class UpdateCourseController extends HttpServlet { private static final long serialVersionUID = 1L; public UpdateCourseController() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String isbn = request.getParameter("isbn"); String bookName = request.getParameter("bookName"); String tname = request.getParameter("tname"); Date createTime = new Date(); Courses course = new Courses(); course.setIsbn(isbn); course.setBookName(bookName); course.setTname(tname); course.setPressTime(createTime); CoursesService courseService = new CoursesService(); Courses query = courseService.getISBN(isbn); if(query == null) { request.setAttribute("msg", "isbn为"+isbn+"的课程不存在!"); request.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward(request, response); return; } courseService.updateCourse(course); request.getRequestDispatcher("/admin/managecoursesUrl").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
时间: 2024-04-07 19:28:45 浏览: 41
UpdateServlet.class
这是一个基于 Java Servlet 技术实现的课程信息管理系统中的更新课程信息的控制器类。它接收一个 HTTP GET 请求,从请求参数中获取需要更新的课程的 ISBN 编号、书名、教师姓名等信息,然后创建一个 Courses 对象并设置相应的属性值,最后调用 CoursesService 类的 updateCourse 方法更新数据库中对应的课程信息。如果要更新的课程不存在,则将错误信息存储到 request 对象的属性中并转发到错误页面进行显示。如果接收到的是 HTTP POST 请求,则会调用 doGet 方法进行处理。
阅读全文