📄 javax.servlet.filter.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--NewPage--><html><head><!-- Generated by javadoc on Fri Apr 04 16:55:35 PST 2003 --><title> Interface javax.servlet.Filter</title></head><body><a name="_top_"></a><pre><a href="packages.html">All Packages</a> <a href="tree.html">Class Hierarchy</a> <a href="Package-javax.servlet.html">This Package</a> <a href="Package-javax.servlet.html">Previous</a> <a href="javax.servlet.FilterChain.html#_top_">Next</a> <a href="AllNames.html">Index</a></pre><hr><h1> Interface javax.servlet.Filter</h1><dl> <dt> public interface <b>Filter</b></dl>A filter is an object than perform filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.<br><br> Filters perform filtering in the <code>doFilter</code> method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks. <p> Filters are configured in the deployment descriptor of a web application <p> Examples that have been identified for this design are<br> 1) Authentication Filters <br> 2) Logging and Auditing Filters <br> 3) Image conversion Filters <br> 4) Data compression Filters <br> 5) Encryption Filters <br> 6) Tokenizing Filters <br> 7) Filters that trigger resource access events <br> 8) XSL/T filters <br> 9) Mime-type chain Filter <br><p><hr><a name="index"></a><h2> <img src="images/method-index.gif" width=207 height=38 alt="Method Index"></h2><dl> <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#destroy()"><b>destroy</b></a>() <dd> Called by the web container to indicate to a filter that it is being taken out of service. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)"><b>doFilter</b></a>(ServletRequest, ServletResponse, FilterChain) <dd> 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. <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o "> <a href="#init(javax.servlet.FilterConfig)"><b>init</b></a>(FilterConfig) <dd> Called by the web container to indicate to a filter that it is being placed into service.</dl><a name="methods"></a><h2> <img src="images/methods.gif" width=151 height=38 alt="Methods"></h2><a name="init(javax.servlet.FilterConfig)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="init"><b>init</b></a><pre> public abstract void init(<a href="javax.servlet.FilterConfig.html#_top_">FilterConfig</a> filterConfig) throws <a href="javax.servlet.ServletException.html#_top_">ServletException</a></pre><dl> <dd> 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<p></dl><a name="doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="doFilter"><b>doFilter</b></a><pre> public abstract void doFilter(<a href="javax.servlet.ServletRequest.html#_top_">ServletRequest</a> request, <a href="javax.servlet.ServletResponse.html#_top_">ServletResponse</a> response, <a href="javax.servlet.FilterChain.html#_top_">FilterChain</a> chain) throws IOException, <a href="javax.servlet.ServletException.html#_top_">ServletException</a></pre><dl> <dd> 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 invokation of the next entity in ther filter chain.<p></dl><a name="destroy()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a><a name="destroy"><b>destroy</b></a><pre> public abstract void destroy()</pre><dl> <dd> 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.<p></dl><hr><pre><a href="packages.html">All Packages</a> <a href="tree.html">Class Hierarchy</a> <a href="Package-javax.servlet.html">This Package</a> <a href="Package-javax.servlet.html">Previous</a> <a href="javax.servlet.FilterChain.html#_top_">Next</a> <a href="AllNames.html">Index</a></pre></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -