Servlet filters' order of execution

后端 未结 2 877
無奈伤痛
無奈伤痛 2020-12-07 14:47

I stumbled upon a bug in my web application that had me scratching my head (and eventually pulling my hair) for a while before I found out what was going on.

Basica

2条回答
  •  清歌不尽
    2020-12-07 15:46

    When the container recives a request, it first finds all the filter mappings with a that matches the request URI. This becomes the first set of filters in the filter chain.Next it finds all the filter mappings with a that matches the request URI. This becomes the second set of filters in the filter chain.In both the sets the filters are executed in the order in which they are declared in the Deployment descriptor(D.D.)

    According to the specs

    The order the container uses in building the chain of filters to be applied for a particular request URI is as follows:

    1. First, the matching filter mappings in the same order that these elements appear in the deployment descriptor.
    2. Next, the matching filter mappings in the same order that these elements appear in the deployment descriptor.

提交回复
热议问题