Adding DispatcherServlet to web.xml

To enable this, we would need to add DispatcherServlet to web.xml. Let's look at how to do that:

    <servlet>       <servlet-name>spring-mvc-dispatcher-servlet</servlet-name>          <servlet-class>         org.springframework.web.servlet.DispatcherServlet       </servlet-class>       <init-param>         <param-name>contextConfigLocation</param-name>         <param-value>/WEB-INF/user-web-context.xml</param-value>       </init-param>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>       <servlet-name>spring-mvc-dispatcher-servlet</servlet-name>       <url-pattern>/</url-pattern>     </servlet-mapping>

The first part is to define a servlet. We are also defining a context configuration location, /WEB-INF/user-web-context.xml. We will define a Spring ...

Get Mastering Spring 5.0 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.