Expert Spring MVC and Web Flow

(Dana P.) #1
Figure 4-4.Sequence for HomeController

Summary


We have built, from the ground up, a Spring MVC application complete with a service layer
and an object model. Nearly all of the configuration work is complete as well, making it quite
easy to add functionality as the application grows.
You have been introduced to many of the core elements of a Spring MVC application,
including the Controller, ModelAndView, ViewResolver, View, and DispatcherServlet. The
Controllers and Views you will build and configure, while the ViewResolverand
DispatcherServlettypically require only configuration.
A Spring MVC application is initialized via the web.xmlfile, the standard configuration file
for a Java web application, but the configuration is performed via the bean definition XML
files such as applicationContext.xmland spring-servlet.xml. Both the DispatcherServlet
and the ContextLoaderListenerare defined in the web.xmlfile, providing the initialization and
bootstrap process for the entire Spring MVC application. Controllers and the ViewResolver
appear in spring-servlet.xml. The service layer and non–web-specific supporting services
appear in applicationContext.xml.
Having built a fully functional application, we will now implement the second use case.
The Search for Flights use case will be much simpler because we’ve completed the initial
configuration of the application. Its implementation will illustrate how Spring MVC handles
XHTML form processing.

64 CHAPTER 4 ■JUMP INTO SPRING MVC


DispatcherServlet HomeController

ModelAndView

Browser FlightService ViewResolver View

Return
an
existing
view
instance

2:handleRequest()

9:Resolve view

11:render()

3:getSpecialDeals()

5:new()
6:addObject( specialDeals )

8:Return ModelAndView

7:setView()

10:Return view

4:Return specialDeals

1:Request home

12:Return render to client
Free download pdf