如何在过滤器中获取 ServletConfig 对象 [英] How to get ServletConfig object in Filter

查看:62
本文介绍了如何在过滤器中获取 ServletConfig 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在应用到该 servlet 的 Filter 中获取 servlet 的 ServletConfig 对象?

Is there any way to get ServletConfig object of the servlet in a Filter applied to that servlet?

编辑->场景是我提到了角色的名字(谁可以访问servlet)在 web.xml 中 serlvet 声明的init-param"中

Edit-> The scenerio is i have mentioned the names of roles(who can access the servlet) in the 'init-param' of the serlvet declaration in web.xml

应用的过滤器将检查(使用 ServletConfig)试图访问 servlet 的人是否被授权(以角色身份)访问它.

The applied filter will check(using ServletConfig) whether the person who is trying to access the servlet is authorized(in roles) to access it or not.

推荐答案

你不能.ServletConfig 绑定到特定的 servlet,就像 FilterConfig 用于过滤器一样.

You can't. ServletConfig is tied to a specific servlet, just like FilterConfig is for filters.

您想在过滤器中访问哪个 servlet 配置?请注意,过滤器不一定需要直接委托给底层 servlet.它可以将请求传递给另一个 servlet,根据某些条件选择 servlet,甚至可以在不触及任何 servlet 的情况下完全处理请求.

Which servlet config you want to access inside a filter? Note that a filter does not necessarily need to delegate to an underlying servlet directly. It can pass request to another servlet, choose servlet based on some condition or even handle the request completely without touching any servlet.

话虽如此,这两个抽象在彼此之间是不可访问的.

That being said these two abstractions are not accessible within each other.

这篇关于如何在过滤器中获取 ServletConfig 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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