3

I am trying to learn spring MVC framework. Dispatcher servlet is suppose to handle all the incoming requests and we achieve that with following configuration :

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

My question is how / is different from /*. When we return the view name, we usually prefix / before the view name like /WEB-INF, so will that request also go through DispatcherServlet. If not why?

tec
  • 41
  • 9
  • 1
    Have a look here http://stackoverflow.com/questions/13843294/what-does-the-double-wildcard-on-a-servlet-mapping-url-pattern-mean – Simon May 16 '15 at 05:48

1 Answers1

2

In a JAVA EE web application, there are 3 parts to URL mappings:

  • Context path (root of your URL)
  • Servlet path (pattern that activated your component)
  • Info path (The trailing path)

E.g. Dispatcher mapped to "/myservlet/", with "root" context

GET /root/myservlet/info

  • /root context path
  • /myservlet servlet path
  • /info info path

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

"/" becomes the container default fallback for the path.

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

Community
  • 1
  • 1
Razvan Manolescu
  • 414
  • 2
  • 10
  • Carefully read http://stackoverflow.com/questions/4140448/difference-between-and-in-servlet-mapping-url-pattern and fix or delete your wrong answer. – BalusC May 16 '15 at 21:05