Can we use regular expressions in web.xml URL patterns?

No, you can’t use a regex there. According to the Java Servlet Specification v2.4 (section srv.11.1), the url-path is interpreted as follows:

  • 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 con- text path and the path info is null.
  • All other strings are used for exact matches only.

No regexes are allowed. Not even complicated wild-cards.

Leave a Comment