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

前端 未结 6 2081
我在风中等你
我在风中等你 2020-11-27 05:02

I am writing a filter to do a specific task but I am unable to set a specific url pattern to my filter. My filter mapping is as follows:



        
6条回答
  •  佛祖请我去吃肉
    2020-11-27 05:22

    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.

提交回复
热议问题