Exemple #1
0
  private void readAllAuthors(HttpServletRequest request, HttpServletResponse response)
      throws SQLException, ServletException, IOException {
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/viewauthor.jsp");
    Integer pageNo = Integer.parseInt(request.getParameter("pageNo"));

    try {
      List<Author> authors = adminService.getAllAuthors(pageNo, 10);
      request.setAttribute("authors", authors);
      rd.forward(request, response);
    } catch (ServletException e) {
      e.printStackTrace();
      rd.forward(request, response);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemple #2
0
  private void deleteAuthor(HttpServletRequest request, HttpServletResponse response)
      throws SQLException, ServletException, IOException {
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/viewauthor.jsp");
    Integer authorId = Integer.parseInt(request.getParameter("authorId"));

    try {
      adminService.deleteAuthor(authorId);
      request.setAttribute("result", "Author Deleted Sucessfully.");
      rd.forward(request, response);
    } catch (ServletException e) {
      request.setAttribute("result", "Author Delete Failed.");
      e.printStackTrace();
      rd.forward(request, response);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemple #3
0
 private void addAuthor(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   RequestDispatcher rd = getServletContext().getRequestDispatcher("/admin.jsp");
   String authorName = request.getParameter("authorName");
   if (authorName.length() < 1 || authorName.length() > 40) {
     rd = getServletContext().getRequestDispatcher("/addauthor.jsp");
     request.setAttribute("result", "Author Name cannot be more than 45 chars!");
     rd.forward(request, response);
   }
   Author author = new Author();
   author.setAuthorName(authorName);
   try {
     adminService.addAuthor(author);
     request.setAttribute("result", "Author Added Sucessfully!");
     rd.forward(request, response);
   } catch (SQLException e) {
     e.printStackTrace();
     rd = getServletContext().getRequestDispatcher("/addauthor.jsp");
     request.setAttribute("result", "Author Add Failed!");
     rd.forward(request, response);
   }
 }