java web.xml 中 <filter> 标签的用途是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4470427/
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-10-30 06:32:42  来源:igfitidea点击:

What is the purpose of <filter> tag in web.xml?

javaservlet-filters

提问by vinoth kumar

What is the purpose of <filter>tag in web.xml?

<filter>web.xml中标签的用途是什么?

回答by duffymo

It allows you to declare servlet filters, which are aspects for HTTP requests. A filter chain can intercept an incoming request and/or an outgoing response and modify it as needed.

它允许您声明 servlet 过滤器,这是 HTTP 请求的方面。过滤器链可以拦截传入的请求和/或传出的响应并根据需要对其进行修改。

A common example is to have a filter that performs a GZIP compression on a response stream if the user's browser can accept it. This improves performance by reducing the number of bytes on the wire, provided that the savings is greater than the time to compress and decompress.

一个常见的例子是有一个过滤器,如果用户的浏览器可以接受它,它会在响应流上执行 GZIP 压缩。这通过减少线路上的字节数来提高性能,前提是节省的时间大于压缩和解压缩的时间。

回答by darioo

For declaring where a Servlet Filtershould be applied. Hereis a nice example of filter usage.

用于声明应在何处应用Servlet 过滤器是过滤器使用的一个很好的例子。