上QQ阅读APP看书,第一时间看更新
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 context in the next step. In the second part, we are defining a servlet mapping. We are mapping a URL / to the DispatcherServlet. So, all requests will be handled by the DispatcherServlet.