Learn Java for Web Development

(Tina Meador) #1

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:



  1. <beans:bean

  2. 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



  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>

  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

  3. <!DOCTYPE html>











  4. Your Book store








  5. Books List







































  6. Author Book Title
    ${book.author.authorName} ${book.bookTitle}









Figure 5-20 illustrates the directory structure of the bookstore application.

Free download pdf