コード例 #1
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String forward = "";
    String action = request.getParameter("action");
    try {
      if (action.equalsIgnoreCase("delete")) {
        int disciplineId = Integer.parseInt(request.getParameter("disciplineId"));
        disciplineDao.delete(disciplineId);
        forward = DisciplineList;
        request.setAttribute("disciplines", disciplineDao.select());

      } else if (action.equalsIgnoreCase("disciplineList")) {
        forward = DisciplineList;
        request.setAttribute("disciplines", disciplineDao.select());
      } else if (action.equalsIgnoreCase("edit")) {
        forward = InsertOrEdit;
        int disciplineId = Integer.parseInt(request.getParameter("disciplineId"));

        Discipline discipline = disciplineDao.getDisciplineById(disciplineId);
        request.setAttribute("discipline", discipline);
      } else if (action.equalsIgnoreCase("back")) {
        forward = Back;
      } else {
        forward = InsertOrEdit;
      }
      RequestDispatcher view = request.getRequestDispatcher(forward);
      view.forward(request, response);

    } catch (DaoException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws IOException {
   Discipline discipline = new Discipline();
   try {
     discipline.setNameDiscipline(request.getParameter("nameDiscipline"));
     ;
     String disciplineId = request.getParameter("disciplineId");
     if (disciplineId == null || disciplineId.isEmpty()) {
       disciplineDao.insert(discipline);
     } else {
       discipline.setId(Integer.parseInt(disciplineId));
       disciplineDao.update(discipline);
     }
     response.sendRedirect(
         request.getContextPath() + "/DisciplineController?action=disciplinelist");
   } catch (DaoException e) {
     e.printStackTrace();
   }
 }