@Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   HttpSession session = request.getSession(false);
   User user = (User) session.getAttribute("user");
   MessageBox messageBox = new MessageBox();
   // Check the permissions.
   if (user.getRole() == UserRole.ADMIN || user.getRole() == UserRole.EDITOR) {
     if (request.getParameter("selectionIds") == null) {
       // The method is called from the chain list page.
       this.doGet(request, response);
     } else {
       // The method is called from the chain delete page.
       String[] selection = (request.getParameter("selectionIds")).split(",");
       List<String> selectionList = chainIdsToListOfTitles(selection);
       for (int i = 0; i < selection.length; i++) {
         ChainService.removeChain(Long.valueOf(selection[i].trim()));
       }
       // Form the success message.
       messageBox.setTitle("The following chains have been successfully deleted:");
       messageBox.setMessages(selectionList);
       Messager.sendMessage(request, messageBox, MessageSeverity.SUCCESS);
       response.sendRedirect(request.getContextPath() + "/ChainList");
     }
   } else {
     // Form the error message.
     messageBox.setTitle(
         "Not enough previlegues to perform the operation. Please contact the administrator.");
     Messager.sendMessage(request, messageBox, MessageSeverity.ERROR);
     response.sendRedirect(request.getContextPath() + "/ChainList");
   }
 }
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // Read the selected ids.
    String[] selection = request.getParameterValues("selected_id");
    if (selection == null || selection.length == 0) {
      // No items have been selected for deletion.
      // Form an error message.
      MessageBox messageBox = new MessageBox();
      messageBox.setTitle("Please select chains you want to delete.");
      Messager.sendMessage(request, messageBox, MessageSeverity.WARNING);
      response.sendRedirect(request.getContextPath() + "/ChainList");
    } else {
      List<String> selectionList = chainIdsToListOfTitles(selection);
      String itemName = "chain";
      // Check whether the name of the items should be plural.
      if (selectionList.size() % 10 != 1) {
        itemName += "s";
      }
      String selectionIds = Utils.arrayToString(selection);

      // Pass the list of selected ids to the view to be displayed.
      request.setAttribute("selectionList", selectionList);
      // Pass the string of ids separated by comma to the view to be
      // passed further to the doPost() method via a hidden input.
      request.setAttribute("selectionIds", selectionIds);
      // Set other attributes.
      request.setAttribute("htmlTitle", "SnippetHub | Chain Delete");
      request.setAttribute("itemName", itemName);
      request.setAttribute("controllerList", "ChainList");
      request.setAttribute("controllerDelete", "ChainDelete");

      response.setHeader("Charset", "UTF-8");
      RequestDispatcher dispatcher =
          request.getRequestDispatcher("WEB-INF/template/page-delete.jsp");
      dispatcher.forward(request, response);
    }
  }