December 28 2015

Spring MVC Dispatcher Servlet

Spring MVC Dispatcher Servlet

Spring Web MVC framework is designed around the Front controller which is DispatcherServlet. DispatcherServlet is a servlet implemented as a subtype of HttpServlet. It is responsible for initializing the Spring Web MVC framework.

DispatcherServlet listens to the incoming requests and dispatches the request to handler,configurable handler mapping, view resolvers, local and theme resolvers. It has to be configured in web.xml

In the below web.xml, DispatcherServlet is declared as servlet to use spring-beans.xml and to intialize WebAplicationContext. According to the servlet-mapping, Web Container will dispatch all the request for the context whose servlet path ends with .htm to DispatcherServlet.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">
 <display-name>springanswersz</display-name>
 <servlet>
 <servlet-name>springDispatcherServlet</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/spring-beans.xml</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
 <servlet-name>springDispatcherServlet</servlet-name>
 <url-pattern>*.html</url-pattern>
 </servlet-mapping>
</web-app>


Copyright © 2014. All rights reserved.

Posted December 28, 2015 by answersz in category Spring

Leave a Comment

Your email address will not be published. Required fields are marked *

*