Java web.xml 过滤器如何工作?您可以将两个过滤器映射到所有页面 (/*) 并指定顺序吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2122455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:47:14  来源:igfitidea点击:

How do web.xml filters work? Can you have two filters map to all pages (/*) and specify the order?

javaservletsspring-securityweb.xml

提问by Kyle

I want to use Spring Security, and it says to map the filter to /***. But I already have a filter mapped to /*, which is the Tuckee URLRewrite filter.

我想使用 Spring Security,它说将过滤器映射到 /***。但是我已经有一个映射到 /* 的过滤器,它是 Tuckee URLRewrite 过滤器。

Is it possible to map two filters to the same thing, and also is there a way to specify the order that the filters get called?

是否可以将两个过滤器映射到同一事物,还有没有办法指定过滤器被调用的顺序?

采纳答案by Bozho

Yes, you can:

是的你可以:

The servlet 2.5 xsd:

servlet 2.5 xsd

The order in which filters are invoked is the order in which filter-mapping declarations that match a request URI for a servlet appear in the list of filter-mapping elements

调用过滤器的顺序是与 servlet 的请求 URI 匹配的过滤器映射声明出现在过滤器映射元素列表中的顺序

i.e. it depends on the order of your <filter-mapping>elements in the web.xml

即这取决于您的<filter-mapping>元素在web.xml