コード例 #1
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    List<Book> booklist = bookService.getAllBooks();
    String title = request.getParameter("title");
    String emailTo = request.getParameter("emailTo");
    String subject = request.getParameter("subject");

    boolean booksFound = false;
    String result = "You searched for \"" + title + "\".<br><br>";
    for (int i = 0; i < booklist.size(); i++) {
      if (booklist.get(i).getTitle().toLowerCase().contains(title.toLowerCase())) {
        result += booklist.get(i).getTitle() + ", " + booklist.get(i).getIsbn() + "<br>";
        booksFound = true;
      }
    }

    if (!booksFound) {
      result = "Your search \"" + title + "\" did not match any books.";
    }

    try {
      MailForm mailForm = new MailForm();
      mailForm.setEmailSubject(subject);
      mailForm.setEmailTo(emailTo);
      mailForm.setMessageText(result);
      emailBean.sendEmail(mailForm);
    } catch (MessagingException e) {
      logger.error(e);
    }

    request.setAttribute("styles", result);
    RequestDispatcher view = request.getRequestDispatcher("result.jsp");
    view.forward(request, response);
  }
コード例 #2
0
ファイル: BookSelect.java プロジェクト: Kanito/pipeline
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    List<Book> booklist = bookService.getAllBooks();
    String title = request.getParameter("title");

    boolean booksFound = false;
    String result = "You searched for \"" + title + "\".<br><br>";
    for (int i = 0; i < booklist.size(); i++) {
      if (booklist.get(i).getTitle().toLowerCase().contains(title.toLowerCase())) {
        result += booklist.get(i).getTitle() + ", " + booklist.get(i).getIsbn() + "<br>";
        booksFound = true;
      }
    }

    if (!booksFound) {
      result = "Your search \"" + title + "\" did not match any books.";
    }

    request.setAttribute("styles", result);
    RequestDispatcher view = request.getRequestDispatcher("result.jsp");
    view.forward(request, response);
  }