|
|
package web.servlet.teacher;
|
|
|
|
|
|
import service.TeacherService;
|
|
|
import service.impl.TeacherServiceImpl;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
@WebServlet("/deleteOptionalCourseServlet")
|
|
|
public class DeleteOptionalCourseServlet extends HttpServlet {
|
|
|
|
|
|
// 处理POST请求的方法
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// 设置请求字符编码为UTF-8,以支持中文字符
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
// 获取请求 "cid",表示要删除的课程ID
|
|
|
String cid = request.getParameter("cid");
|
|
|
|
|
|
// 创建教师服务的实现类实例
|
|
|
TeacherService service = new TeacherServiceImpl();
|
|
|
|
|
|
// 调用服务层方法,根据课程ID删除课程
|
|
|
service.deleteCourseById(cid);
|
|
|
|
|
|
// 请求转发到教师可选课程的Servlet,以更新课程列表
|
|
|
request.getRequestDispatcher("/teacherOptionalCourseServlet").forward(request, response);
|
|
|
}
|
|
|
|
|
|
// 处理GET请求的方法
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// 对于GET请求,调用doPost方法进行处理
|
|
|
doPost(request, response);
|
|
|
}
|
|
|
}
|
|
|
//public class DeleteOptionalCourseServlet extends HttpServlet {
|
|
|
//
|
|
|
// // 处理POST请求的方法
|
|
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// // 设置请求字符编码为UTF-8,以支持中文字符
|
|
|
// request.setCharacterEncoding("utf-8");
|
|
|
//
|
|
|
// // 获取请求 "cid",表示要删除的课程ID
|
|
|
// String cid = request.getParameter("cid");
|
|
|
//
|
|
|
// // 创建教师服务的实现类实例
|
|
|
// TeacherService service = new TeacherServiceImpl();
|
|
|
//
|
|
|
// // 调用服务层方法,根据课程ID删除课程
|
|
|
// service.deleteCourseById(cid);
|
|
|
//
|
|
|
// // 请求转发到教师可选课程的Servlet,以更新课程列表
|
|
|
// request.getRequestDispatcher("/teacherOptionalCourseServlet").forward(request, response);
|
|
|
// }
|
|
|
//
|
|
|
// // 处理GET请求的方法
|
|
|
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// // 对于GET请求,调用doPost方法进行处理
|
|
|
// doPost(request, response);
|
|
|
// }
|
|
|
//}
|