Learn Java for Web Development

(Tina Meador) #1

240 CHAPTER 5: Building Java Web Applications with Spring Web MVC


We will go through each of the components illustrated in Figure 5-17. Figure 5-18 illustrates the
content of the generated web.xml file.


Figure 5-18. Generated web.xml


This is the typical configuration for a Spring MVC-based application with a declaration for the following:


   Spring’s ContextLoaderListener
 Spring’s DispatcherServlet
 Spring configuration file root-context.xml
 Spring configuration file servlet-context.xml
 The URL mapping for Spring’s DispatcherServlet

We will look at the use of each one of these, but before that, we will modify web.xml. In the Spring
MVC template project, the web.xml file it generates supports Servlet 2.5. In this chapter, we will use
Servlet 3.0 (the tcServer that comes with STS is built on top of Apache Tomcat 7, which already
supports Servlet 3.0), so we need to change the XML header from 2.5 to 3.0 too. Listing 5-36 shows
the revised tag.

Free download pdf