Mapping Servlet URL for Controller Template

I am trying to learn the spring MVC framework. The dispatcher servlet must handle all incoming requests and we achieve this with the following configuration:

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

      

My question is how / differs from / *. When we return the view name, we usually prefix / before the view name, for example / WEB -INF, so this request will also go through the DispatcherServlet. If not?

+3


source to share


1 answer


There are 3 parts of url mappings in JAVA EE web application:

  • Context path (root of your url)
  • Servlet path (template that activated your component)
  • Information path (final path)

eg. The dispatcher associated with "/ myservlet /" with the context "root"

GET / root / myservlet / info



  • / path to root content
  • / myservlet path servlet
  • / info info path

" / " and " / * " will match any token after that, but " / " will only match if an explicit mapping for path is provided (in this case, if there is a servlet mapping for / myservlet / info).

" / " becomes the default container for the path.

" / * " overrides everything in the path. As mentioned here , this is great for filter mappings.

+1


source







All Articles