|
|
package web.servlet.student;
|
|
|
|
|
|
import service.NotifyService;
|
|
|
import service.StudentService;
|
|
|
import service.impl.NotifyServiceImpl;
|
|
|
import service.impl.StudentServiceImpl;
|
|
|
|
|
|
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("/deleteStudentServlet")
|
|
|
public class DeleteStudentServlet extends HttpServlet {
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
HttpSession session = request.getSession();
|
|
|
String studentid = request.getParameter("s_id");
|
|
|
StudentService service = new StudentServiceImpl();
|
|
|
service.deleteStudentById(studentid);
|
|
|
// request.getRequestDispatcher("/findStudentByPageServlet").forward(request,response);
|
|
|
response.sendRedirect("findStudentByPageServlet");
|
|
|
}
|
|
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
doPost(request,response);
|
|
|
}
|
|
|
}
|
|
|
//package web.servlet.student;
|
|
|
//
|
|
|
//import service.NotifyService;
|
|
|
//import service.StudentService;
|
|
|
//import service.impl.NotifyServiceImpl;
|
|
|
//import service.impl.StudentServiceImpl;
|
|
|
//
|
|
|
//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("/deleteStudentServlet")
|
|
|
//// 删除学生的Servlet
|
|
|
//public class DeleteStudentServlet extends HttpServlet {
|
|
|
//
|
|
|
// // 处理POST请求
|
|
|
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// // 设置请求的字符编码为UTF-8
|
|
|
// request.setCharacterEncoding("utf-8");
|
|
|
//
|
|
|
// // 获取当前会话
|
|
|
// HttpSession session = request.getSession();
|
|
|
//
|
|
|
// // 获取要删除的学生ID
|
|
|
// String studentid = request.getParameter("s_id");
|
|
|
//
|
|
|
// // 创建学生服务的实例
|
|
|
// StudentService service = new StudentServiceImpl();
|
|
|
//
|
|
|
// // 调用服务方法通过学生ID删除学生
|
|
|
// service.deleteStudentById(studentid);
|
|
|
//
|
|
|
// // 重定向到查找学生的页面
|
|
|
// response.sendRedirect("findStudentByPageServlet");
|
|
|
// // 如果需要使用转发,可以使用下面的代码
|
|
|
// // request.getRequestDispatcher("/findStudentByPageServlet").forward(request, response);
|
|
|
// }
|
|
|
//
|
|
|
// // 处理GET请求,直接调用doPost方法
|
|
|
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
// doPost(request, response);
|
|
|
// }
|
|
|
//}
|