在JSF中,无论如何都要检查是否为应用程序注册了过滤器?我有一些需要过滤器的功能,并且我想生成更好的错误消息来解释过滤器不存在并且功能将被禁用。基本上,给出一个理论过滤器:
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>com.example.SomeFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
我想要某种方式检查.isRegistered("com.example.SomeFilter")
。
我考虑打印堆栈跟踪并检查过滤器类是否存在,但这似乎是一个hacky解决方案。
答案 0 :(得分:2)
您可以访问FilterRegistration
。{/ p>中的ServletContext
ServletContext ctx = (ServletContext)FacesContext.getCurrentInstance()
.getExternalContext().getContext();
if(ctx.getFilterRegistration("SomeFilter") != null){
...
}