Search code examples
springspring-mvcservletsdispatcher

Dispatcher Servlet Mapping - Spring Framework


I am new to Spring Framework and I was wondering why every time we create a new Spring project and we set the dispatcher mapping as / instead of the default *.htm.

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Thanks!


Solution

  • 1.<url-pattern>*.html</url-pattern>:

    we are specifying the servlet class DispatcherServlet that acts as the front controller in Spring Web MVC. All the incoming request for the .html file will be forwarded to the DispatcherServlet.

    2.<url-pattern>/</url-pattern> :

    A mapping that contains the pattern <url-pattern>/</url-pattern> matches a request if no other pattern matches. This is the default mapping. The servlet mapped to this pattern is called the default servlet.The default mapping is often directed to the first page of an application.

    Thanks..