0

I tried to google this question but, it seems google search engine reads it as some special character.

So what is the differences between mapping a server to " / " and to " /* " ?

Adelin
  • 18,144
  • 26
  • 115
  • 175

3 Answers3

2

SRV.11.2 Specification of Mappings

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 is null.

All other strings are used for exact matches only.

My emphasis

<servlet-mapping>
        <servlet-name>XServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

If you see mapping XServlet that's to matching all requests and every request hits XServlet

Where as

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

Now XServlet is my default servlet of application, which serves static resources.

Just to clarify further confusions:How to access static resources when mapping a global front controller servlet on /*

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

The pattern / will make your servlet the default servlet for the app, whereas the pattern /* will force everything through your servlet..

aquaraga
  • 4,138
  • 23
  • 29
  • and what are the differences between the default servlet and the one that everything is forced through it ? Which one is to come first ? – Adelin Oct 28 '13 at 09:33
0

If you map to / only one url will match : your server url (http://my.example.org/). If you map to /* a lot of url will match : http://my.example.org/logo.gif, http://my.example.org/index.jsp, http://my.example.org/detail.html and so on.

Using / maybe useful if you only have 1 servlet and if your resources aren't at the root directory of your webapp (which should not be the case anyway).

Julien
  • 2,544
  • 1
  • 20
  • 25