在过滤器中获取在web.xml配置的初始化参数
例如
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>com.bx.ResourceFilter</filter-class>
<init-param>
<param-name>dd</param-name>
<param-value>ddd</param-value>
</init-param>
</filter>
在ResourceFilter过滤器的处置化方法中获取param-value代码如下所示:
public void init(FilterConfig filterConfig) throws ServletException {
Enumeration<String> enums = filterConfig.getInitParameterNames();
while (enums.hasMoreElements()) {
String param = (String) enums.nextElement();
System.out.println(param + ":" + filterConfig.getInitParameter(param));
}
}
本文地址:http://www.yayihouse.com/yayishuwu/chapter/1096