Issue
I have an Java Servlet that I want to execute only if the path requested DOESN'T have any extension, if the path ends with any extension(css, jsp, js...) it must continue normally, without calling the servlet.
How can I do this?
Solution
No you can't have such a regex in servlet mapping.
According to servlet specs:
- 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.
However you can have a default filter (/) to handle all such cases.
Answered By - Yati Sawhney
Answer Checked By - David Marino (JavaFixing Volunteer)