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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Carefully read stackoverflow.com/questions/4140448/… and fix or delete your wrong answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.