Learn Java for Web Development

(Tina Meador) #1
CHAPTER 2: Building Web Applications Using Servlets and JSP 103

4.try {
5.BookDAO bookDao = new BookDAOImpl();
6.List bookList = bookDao.searchBooksByKeyword(keyWord);
7.
8.request.setAttribute("bookList", bookList);
9.
10.} catch (Exception e) {
11.System.out.println(e);
12.}
13.}
14.


   Line 6: This obtains the bookList based on the search keyword by invoking the
searchBooksByKeyword() method defined in BookDAO. We used this method in
Chapter 1 when we built the data-access layer for our web application.

Summary


This chapter introduced servlets and JSP and showed you how to make your first web application
using these web components. Then the chapter implemented the real-world MVC-based Java web
application, a bookstore using servlets and JSP. In the next chapter, we will augment this application
to use the best practice of separating the business-logic concerns from the presentation using JSTL
and Expression Language.

Free download pdf