过滤器核心接口对象

Filter、FilterConfig、FilterChain是过滤器的三个核心接口对象,位于javax.servlet包中。

1、Filter接口

每一个过滤器对象都要直接或间接的实现Filter接口,在Filter接口中定义了三个方法,分别是:
过滤器初始化方法,在过滤器初始化时调用。
public void init(FilterConfig fcongfig)throws ServletException
对请求进行过滤处理方法。

public void doFilter(ServletRequest request,ServletResponse respone,FilterChain chain)


2、FilterConfig接口

FilterConfig接口主要用于获取过滤器中的配置信息,某方法主要由:
用于获取过滤器的名字。
public String getFilterName()
获取Servlet上下文
public ServletContext getServletContext()
获取过滤器初始化参数。
public String getlnitParameter(String name)

获取过滤器的所有初始化参数


3、FilterChain接口

FilterChain接口中只有一个方法。
此方法用于将过滤器后的请求传递给下一个过滤器,如果此过滤器已经是过滤器链中
的最后一个过滤器,那么,请求将传给目标资源。
public void doFilter(ServletRequest request,ServletResponse response)throws
IOException ServleException

你可能感兴趣的:(过滤器核心接口对象)