a Learner
a Learner

Reputation: 5042

Url mapping of servlets

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?

Upvotes: 1

Views: 707

Answers (2)

Aniket Kulkarni
Aniket Kulkarni

Reputation: 12983

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.

Upvotes: 2

Charles Stevens
Charles Stevens

Reputation: 1584

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.

Upvotes: 1

Related Questions