248 CHAPTER 5: Building Java Web Applications with Spring Web MVC
resolver to identify which view should be returned to the user. In this case, the BookController
returns a ModelAndView object named bookList. The fragment of the view resolver in
bookstore-servlet.xml (from Listing 5-41) is shown here:
- <beans:bean
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
Based on the definition, the view resolver finds the file using the following mechanism:
Prefix + ModelAndView name + suffix, which translates to : /WEB-INF/jsp/bookList.jsp
ModelAndView.addObject("bookList", bookService.getBookList()) adds the book data returned by
getBookList() to the model named bookList, which is formatted and rendered by the view.
Finally, the servlet engine renders the response via the specified JSP illustrated in Listing 5-43.
Listing 5-43. View
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <!DOCTYPE html>
Your Book store
Books List
Author
Book Title
${book.author.authorName}
${book.bookTitle}
Figure 5-20 illustrates the directory structure of the bookstore application.