1

Consider following code snippet of web.xml:

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>

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

In above code snippet what does

<url-pattern>/</url-pattern>

represents?

is /and /* in above url-pattern same thing?

a Learner
  • 4,944
  • 10
  • 53
  • 89

2 Answers2

2

is /and /* in above url-pattern same thing?

No.

JSR-000315 Java Servlet 3.0 specification

SRV.11.2 Specification of Mappings

In the Web application deployment descriptor, the following syntax is used to define 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.
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
1

Double asterisk

/** will match any number of (0 or more) levels in a path, eg. it would match both /file and /some/path/file.

Single Asterisk

A single asterisk /* only matches 0 or more characters (not path levels) so it would match /file but not /some/path/file.

No Asterisk

A single slash / would only match the root path.

Community
  • 1
  • 1
Charles Stevens
  • 1,568
  • 15
  • 30