servlet 过滤器是否可以确定哪个 servlet 将处理请求 [英] Is it possible for a servlet filter to work out which servlet will handle the request

查看:62
本文介绍了servlet 过滤器是否可以确定哪个 servlet 将处理请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个执行日志记录的过滤器,如果请求将在某个 servlet 结束,我需要禁用此日志记录.

I'm writing a filter that performs logging and I need to disable this logging if the request is going to end up at a certain servlet.

有没有办法让过滤器知道哪个 servlet 将处理请求?

Is there any way for the filter to know which servlet will handle the request?

推荐答案

您可能希望设置 servlet 过滤器映射,以便在完全请求特定 servlet 时不触发它.

You might want to setup servlet filter mapping to not fire it in case of requests for particular servlet altogether.

示例配置可能如下所示,假设有一个不应受过滤器影响的 DefaultServlet 和两个必须受到影响的其他 servlet FirstServlet 和 SecondServlet.

Example configuration could look like this assuming that there is one DefaultServlet that should not be impacted by filter and two other servlets FirstServlet and SecondServlet which have to be affected.

<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <servlet-name>FirstServlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <servlet-name>SecondServlet</servlet-name>
</filter-mapping>

这篇关于servlet 过滤器是否可以确定哪个 servlet 将处理请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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