什么是OncePerRequestFilter? [英] What is OncePerRequestFilter?

查看:1486
本文介绍了什么是OncePerRequestFilter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说org.springframework.web.filter.OncePerRequestFilter"保证每个请求只执行一次".在什么情况下,每个请求可能多次执行过滤器?

Documentation says org.springframework.web.filter.OncePerRequestFilter "guarantees to be just executed once per request". Under what circumstances a Filter may possibly be executed more than once per request?

推荐答案

在什么情况下,每个请求可能多次执行过滤器?

Under what circumstances a Filter may possibly be executed more than once per request?

您可以在过滤器链上多次放置过滤器.

You could have the filter on the filter chain more than once.

可以使用请求分派器将请求分派到不同(或相同)的servlet.

The request could be dispatched to a different (or the same) servlet using the request dispatcher.

Spring Security中的一个常见用例是,身份验证和访问控制功能通常被实现为位于主应用程序servlet前面的过滤器.当使用请求分派器分派一个请求时,它必须再次经过过滤器链(或可能是另一个过滤器),然后才能到达要处理的servlet.问题在于,某些安全筛选器操作仅应针对请求执行一次.因此需要过滤器.

A common use-case is in Spring Security, where authentication and access control functionality is typically implemented as filters that sit in front of the main application servlets. When a request is dispatched using a request dispatcher, it has to go through the filter chain again (or possibly a different one) before it gets to the servlet that is going to deal with it. The problem is that some of the security filter actions should only be performed once for a request. Hence the need for this filter.

这篇关于什么是OncePerRequestFilter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆