Introduction
A Spring web application uses a MVC (Model-View-Controller) architecture to process HTTP requests, as shown in the following image:
An HTTP request, identified by a route (for example, /user/list
), executes a controller method. A view, usually a JSP file, is rendered afterwards and the resulting HTML is sent back as a response.
In this chapter, we will start by creating a controller and view. Then, you'll learn how to retrieve URL parameters from a controller method. We'll cover two standard ways to reduce code repetition with page templates and URL prefixes. We will finish with more advanced topics related to controllers and views: interceptors and internationalization.
The recipes in this chapter will work with a project similar to the one in the Creating a Spring web application recipe in Chapter 1, Creating a Spring Application, with a Spring configuration class annotated with @EnableWebMvc
and scanning a Java package dedicated to controller classes:
@Configuration...