I'm new to spring framework I today I ran into dispatcher servlet configuration in web.xml file and i came up with a question concerning url pattern like this syntax /. So what does actually the "/" symbol apply in case I deploy web application in tomcat server as following: host:port/ or host:port/myWeb/
The pattern-savvy reader will recognize that the DispatcherServlet is an expression of the “Front Controller” design pattern (this is a pattern that Spring Web MVC shares with many other leading web frameworks). In the preceding example, all requests ending with . form will be handled by the example DispatcherServlet .
The DispatcherServlet is the front controller in Spring web applications. It's used to create web applications and REST services in Spring MVC. In a traditional Spring web application, this servlet is defined in the web. xml file.
The url-pattern element of a servlet-mapping or a filter-mapping associates a filter or servlet with a set of URLs. When a request arrives, the container uses a simple procedure for matching the URL in the request with a url-pattern in the web. xml file.
A typical MVC database driven Spring MVC application requires a lot of configuration such as dispatcher servlet, a view resolver, Jackson, data source, transaction manager, among many others. Spring Boot auto-configures a Dispatcher Servlet if Spring MVC jar is on the classpath.
The pattern /
will make your servlet the default servlet for the app, meaning it will pick up every pattern that doesn't have another exact match.
- A string beginning with a / character and ending with a
/*
suffix is used for path mapping.- A string beginning with a
*.
prefix is used as an extension mapping.- A string containing only the
/
character indicates the default servlet of the application. In this case the servlet path is the request URI minus the context path and the path info isnull
.- All other strings are used for exact matches only.
- The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
- The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the
/
character as a path separator. The longest match determines the servlet selected.- If the last segment in the URL path contains an extension (e.g.
.jsp
), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last.
character.- If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a default servlet is defined for the application, it will be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With