`
king_tt
  • 浏览: 2300460 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Java-Filter-FilterChain-FilterConfig源码

 
阅读更多
public interface Filter {

	/** 
	* Called by the web container to indicate to a filter that it is being placed into
	* service. The servlet container calls the init method exactly once after instantiating the
	* filter. The init method must complete successfully before the filter is asked to do any
	* filtering work. <br><br>

     	* The web container cannot place the filter into service if the init method either<br>
        * 1.Throws a ServletException <br>
        * 2.Does not return within a time period defined by the web container 
	*/
	public void init(FilterConfig filterConfig) throws ServletException;
	
	
	/**
	* The <code>doFilter</code> method of the Filter is called by the container
	* each time a request/response pair is passed through the chain due
	* to a client request for a resource at the end of the chain. The FilterChain passed in to this
	* method allows the Filter to pass on the request and response to the next entity in the
	* chain.<p>
	* A typical implementation of this method would follow the following pattern:- <br>
	* 1. Examine the request<br>
	* 2. Optionally wrap the request object with a custom implementation to
	* filter content or headers for input filtering <br>
	* 3. Optionally wrap the response object with a custom implementation to
	* filter content or headers for output filtering <br>
	* 4. a) <strong>Either</strong> invoke the next entity in the chain using the FilterChain object (<code>chain.doFilter()</code>), <br>   
	** 4. b) <strong>or</strong> not pass on the request/response pair to the next entity in the filter chain to block the request processing<br>
	** 5. Directly set headers on the response after invocation of the next entity in the filter chain.
	**/
    public void doFilter ( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException;

	/**
	* Called by the web container to indicate to a filter that it is being taken out of service. This 
	* method is only called once all threads within the filter's doFilter method have exited or after
	* a timeout period has passed. After the web container calls this method, it will not call the
	* doFilter method again on this instance of the filter. <br><br>
	* 
     	* This method gives the filter an opportunity to clean up any resources that are being held (for
	* example, memory, file handles, threads) and make sure that any persistent state is synchronized
	* with the filter's current state in memory.
	*/

	public void destroy();


}

public interface FilterChain {
	
	/**
	* Causes the next filter in the chain to be invoked, or if the calling filter is the last filter
	* in the chain, causes the resource at the end of the chain to be invoked.
	*
	* @param request the request to pass along the chain.
	* @param response the response to pass along the chain.
	*
	* @since 2.3
	*/
	
    public void doFilter ( ServletRequest request, ServletResponse response ) throws IOException, ServletException;

}


public interface FilterConfig {

	/** 
	* Returns the filter-name of this filter as defined in the deployment descriptor. 
	*/
	
	public String getFilterName();


 /**
     * Returns a reference to the {@link ServletContext} in which the caller
     * is executing.
     *
     *
     * @return		a {@link ServletContext} object, used
     *			by the caller to interact with its servlet 
     *                  container
     * 
     * @see		ServletContext
     *
     */

    public ServletContext getServletContext();
    
    /**
     * Returns a <code>String</code> containing the value of the 
     * named initialization parameter, or <code>null</code> if 
     * the parameter does not exist.
     *
     * @param name	a <code>String</code> specifying the name
     *			of the initialization parameter
     *
     * @return		a <code>String</code> containing the value 
     *			of the initialization parameter
     *
     */

    public String getInitParameter(String name);


    /**
     * Returns the names of the filter's initialization parameters
     * as an <code>Enumeration</code> of <code>String</code> objects, 
     * or an empty <code>Enumeration</code> if the filter has
     * no initialization parameters.
     *
     * @return		an <code>Enumeration</code> of <code>String</code> 
     *			objects containing the names of the filter's 
     *			initialization parameters
     *
     *
     *
     */

    public Enumeration getInitParameterNames();




}


分享到:
评论

相关推荐

    JSP-Filter的简单练习

    通过`FilterChain`对象,我们可以依次调用下一个Filter,直到请求被处理完。此外,Filter的执行顺序取决于它们在`web.xml`中的配置顺序。 **六、Filter与Servlet的区别** Filter与Servlet的主要区别在于,Servlet...

    java中的filter

    在Java Web开发中,`Filter`(过滤器)是一个至关重要的概念,它允许开发者在请求到达Servlet之前或从Servlet响应返回客户端之前进行拦截处理。`Filter`是Java Servlet API的一部分,定义在`javax.servlet.Filter`...

    过滤器(filter) 例子源码

    在Java Web开发中,过滤器(Filter)是一个非常重要的组件,它允许开发者在请求被处理之前或之后执行一些预定义的任务。本篇文章将基于提供的标题和描述,详细讲解过滤器的概念、工作原理以及如何通过源码实现一个...

    XSSFilter源码

    ### XSSFilter源码详解 #### 一、XSSFilter概览 XSSFilter是一种用于防止跨站脚本攻击(Cross-Site Scripting,简称XSS)的安全组件。它通过过滤HTTP请求中的潜在恶意数据来阻止XSS攻击的发生。在本文档中,我们将...

    Java gzip压缩源码 web程序必备

    本文将深入探讨Java中的Gzip压缩源码及其在Web程序中的应用。 首先,我们要了解Gzip的基础知识。Gzip是一种文件格式,用于压缩和解压缩数据,广泛应用于网络传输。它采用DEFLATE算法,这是LZ77压缩算法和霍夫曼编码...

    Filter解决中文乱码

    本篇文章将详细讲解如何使用Filter来解决中文乱码问题,并提供相关源码和配置示例。 首先,我们需要理解为什么会出现中文乱码。乱码通常是由字符编码不一致导致的。例如,客户端(浏览器)发送的请求使用UTF-8编码...

    java自学===Filter类的应用,验证用户

    1. 初始化:当Filter首次被调用时,会触发`init(FilterConfig config)`方法。在这里,我们可以配置Filter的初始化参数,如从web.xml或Java配置中读取。 2. 过滤:每当匹配的请求到达时,`doFilter(ServletRequest ...

    JAVA过滤器及原理

    Java过滤器(Filter)是Java Web开发中的一个重要概念,它主要应用于Servlet容器中,如Tomcat、Jetty等。过滤器允许我们在数据处理前后插入自定义逻辑,对请求和响应进行拦截、修改或增强。本教程将深入讲解Java过滤...

    购物车源码

    import java io IOException; import javax servlet Filter; import javax servlet FilterChain; import javax servlet FilterConfig; import javax servlet RequestDispatcher; import javax servlet ...

    filter_filter_源码.zip

    尽管没有提供具体的标签,但我们可以从文件名推测这可能涉及到Java编程语言,因为".rar"通常与Java相关的项目或源码一起出现。 过滤器模式的核心思想是定义一个过滤接口,该接口包含一个处理输入并产生输出的方法。...

    使用filter拦截servlet和jsp页面的内容,进行过滤后输出

    Filter是Java Servlet API的一部分,它允许开发者在请求到达目标Servlet或JSP之前以及响应离开Servlet之后对其进行处理。通过实现javax.servlet.Filter接口,我们可以定义自己的过滤规则,例如检查用户权限、字符...

    Filter(过滤器)简介和工作原理

    在Java Web开发中,Filter(过滤器)是Servlet API中的一个重要组成部分,它允许开发者在请求被发送到目标资源(如Servlet、JSP页面)之前和之后进行处理。Filter可以用来实现诸如数据校验、字符编码转换、登录检查...

    filter 过滤用户权限

    本篇将详细探讨`filter`如何用于过滤非登录用户的权限控制,以及相关的源码实例。 一、Filter基本概念 在Java Servlet规范中,Filter是一个接口,它允许开发者在请求到达Servlet之前对其进行拦截和处理,也可以在...

    JavaWeb开发几个常用的过滤器源码

    这里我们将深入探讨标题中提到的几个常用的过滤器及其源码实现。 首先,我们来看第一个过滤器:防止浏览器缓存页面的过滤器。这个过滤器的主要目的是确保每次用户访问页面时,都能获取到服务器最新更新的内容,而...

    filter 修改jsp servlet response返回的内容

    在IT行业中,尤其是在Web开发领域,`filter`(过滤器)是Java Servlet技术的一个关键组件,它允许开发者在请求被处理之前或者响应被发送到客户端之后进行拦截和修改。本篇我们将深入探讨如何使用`filter`来修改JSP...

    (四)Jsp filter的简单使用

    在Java Web开发中,Servlet Filter是实现动态网页(JSP)功能增强的重要组件。Filter接口允许我们对HTTP请求和响应进行拦截处理,它提供了在请求到达目标Servlet或JSP之前对其进行预处理以及在响应离开Servlet之后...

    Servlet过滤器的简单使用源码+文档

    Servlet过滤器是基于Java的Servlet API实现的,主要通过实现`javax.servlet.Filter`接口来创建。`Filter`接口定义了三个核心方法:`doFilter()`, `init()`, 和 `destroy()`。`doFilter()`方法是过滤器的核心,每当有...

    Filter应用程序

    Filter的定义在`javax.servlet.Filter`接口中,包含三个核心方法:`init(FilterConfig config)`用于初始化Filter,`doFilter(ServletRequest request, ServletResponse response, FilterChain chain)`是过滤的核心...

    过滤多个servlet

    总的来说,Servlet Filter是Java Web开发中的一个重要工具,它允许我们在请求到达目标Servlet之前进行预处理,并在响应返回之后进行后处理。通过合理配置,一个Filter可以应用于多个Servlet,从而实现代码复用和高效...

    关于处理中文乱码问题 Filter 代码

    本文将重点解析“关于处理中文乱码问题 Filter 代码”的相关知识点,并结合Java Servlet API进行详细讲解。 首先,我们要理解什么是Filter(过滤器)。在Java Web开发中,Filter是Servlet API的一部分,它允许我们...

Global site tag (gtag.js) - Google Analytics