过滤器参数化
第一种:注解过滤器参数
@WebFilter(filterName="EncodingFilter",urlPatterns= {"/*"}, initParams= { @WebInitParam(name="encoding",value="UTF-8") }) @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub encoding = filterConfig.getInitParameter("encoding"); }
第二种:xml配置
<filter> <filter-name>MyFirstFilter</filter-name> <filter-class>com.imooc.filter.FirstFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter>
UrlPattern设置过滤范围