不清楚为什么doFilter过滤器会执行两次,求教
以下是我过滤器部分代码
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
log.info(">>>>>>>>>>>>>>>>>>>> doFilter <<<<<<<<<<<<<<<<<<<<");
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
//获取 API
String api = request.getRequestURI();
log.info(">>>>> api: {}", api);
//如果配置为白名单路径,则放行
if (!CollectionUtil.isEmpty(WHITE_LiST_API)) {
for (String WHITE_API : WHITE_LiST_API) {
if (api.contains(WHITE_API)) {
log.info(">>>>> 在白名单内");
filterChain.doFilter(servletRequest, servletResponse);
return;
}
}
}
以下是执行结果
看了一下你的描述,可能有如下情况:
可能是被双重注册,比如同时加了
@WebFilter
和@Component
,去掉@Component
就行也可能是前端发起多次请求(浏览器的话打开网络监听看一下),检查前端代码