Servlet mapping versus request mapping
The servlet mapping specifies which web container of the Java servlet should be invoked for a given URL. It maps the URL patterns to servlets. When there is a request from a client, the servlet container decides which servlet it should forward the request to based on the servlet mapping. In our case, we mapped all incoming requests to DispatcherServlet
.
In contrast, request mapping guides the DispatcherServlet
which controller method it needs to invoke as a response to the request based on the request path. In our case, we mapped the /welcome
request path to the welcome
method of the HomeController
class.
Pop quiz - servlet mapping
Considering the following servlet mapping, identify the possible matching URLs: ...
Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.