I'm trying to figure out in which order web filters are configured to be executed. I use Servlet 3.1.0 API and apache tomcat 8.5.32. I assume that they are divided into two sets, the ones by url pattern and the ones by servlet name. But how servlet container determines in which order to pick out the filter from each set? I made a test with @WebFilter annotation with exactly two same filters, which differ by name. I found out that filter with name "filterD" executed first, then - "filterB". Then I tried to change the order by placing simple configuration in web.xml like so:
<filter-mapping>
<filter-name>filterB</filter-name>
<url-pattern />
</filter-mapping>
<filter-mapping>
<filter-name>filterD</filter-name>
<url-pattern />
</filter-mapping>
I still see filterD executed before filterB. Why it happens so? Those two filters are configured like so:
@WebFilter(filterName = "filterB", urlPatterns = "/hello")
@WebFilter(filterName = "filterD", urlPatterns = "/hello")