FilterConfig的用法是什么

FilterConfig的用法:
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
FilterConfig可以从web.xml当中取得一些有关Filter参数,当Web应用启动时就可以获得了。



例 1.2.9

package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
public class MarkToWinFilter implements Filter {
    public void destroy() {
    }
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
    }
    protected FilterConfig filterConfig;
    public void init(FilterConfig fConfig) throws ServletException {
        this.filterConfig = fConfig;
        System.out.println(filterConfig.getInitParameter("name"));
    }
}



在web.xml中:
    <filter>
        <filter-name>MarkToWinFilter</filter-name>
        <filter-class>com.MarkToWinFilter</filter-class>
            <init-param>
                  <param-name>name</param-name>
                  <param-value>mark-to-win</param-value>
           </init-param>
    </filter>
  <filter-mapping>
      <filter-name>MarkToWinFilter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>