DeleteServlet.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.it.servlet;
  2. import java.io.IOException;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import com.it.service.CourseService;
  8. import com.it.service.DisciplineService;
  9. import com.it.service.impl.CourseServiceImpl;
  10. import com.it.service.impl.DisciplineServiceImpl;
  11. /**
  12. * Servlet implementation class DeleteServlet
  13. */
  14. public class DeleteServlet extends HttpServlet {
  15. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  16. request.setCharacterEncoding("UTF-8");
  17. try {
  18. String name = request.getParameter("name");
  19. String level = name.substring(name.length()-2, name.length());
  20. name = name.substring(0, name.length() - 2);
  21. if(level.equals("ds"))
  22. {
  23. DisciplineService disciplineService = new DisciplineServiceImpl();
  24. disciplineService.delete(name);
  25. CourseService courseService = new CourseServiceImpl();
  26. courseService.deleteByDiscipline(name);
  27. }else if(level.equals("cs")){
  28. CourseService courseService = new CourseServiceImpl();
  29. courseService.delete(name);
  30. }
  31. request.getRequestDispatcher("DisciplineListServlet").forward(request, response);
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  38. */
  39. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  40. // TODO Auto-generated method stub
  41. doGet(request, response);
  42. }
  43. }