Learn Java for Web Development

(Tina Meador) #1
CHAPTER 5: Building Java Web Applications with Spring Web MVC 227

for(Book b: bookList){
System.out.println(b.getId()+"--"+b.getBookTitle());
}
}
}


In this section, you learned the key objectives of the Spring Framework, which aims to simplify the
complexity that trickles into any enterprise application via tight coupling, cross-cutting concerns,
and boilerplate code. In the next section, we will implement the web layer using the Web MVC
module of the Spring Framework.


Building Web Application with Spring Web MVC


In Chapter 1, Spring Web MVC provided the Model-View-Controller architecture and myriad of
components that together help you develop loosely coupled web applications built on the Spring
IoC container.


Spring Web MVC Architecture

Spring’s Web MVC framework, like many other web MVC frameworks, is request-driven, designed
around a central servlet called DispatcherServlet that dispatches requests to controllers and
offers other functionality that facilitates the development of web applications. DispatcherServlet
implements one of the Java EE web-tier patterns, called Front Controller. As such,
DispatcherServlet acts as the front controller of the Spring MVC framework, and every web request
has to go through it so that it can control and administer the entire request-handling process. The
request-processing workflow of the Spring Web MVC DispatcherServlet is illustrated in Figure 5-6.


Handler Mapping

Controller

Request
Request

Request

ModelAndView

Controller

View Resolver

View

View Name

View
Model

Response

Response

Dispatcher
Servlet

Figure 5-6. Request-processing workflow of the Spring Web MVC DispatcherServlet

Free download pdf