以获取Filer元素里设置的参数为例
先在web.xml文件中配置如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<filter>
<!--定义过滤器-->
<filter-name>filter</filter-name>
<!--这个自定义类 在项目中的某个包中-->
<filter-class >com.ou.book.filter.UrlFilter</filter-class>
<!--设置默认的参数-->
<init-param>
<param-name>value</param-name>
<param-value>nihao,wula,haha,heihei</param-value>
</init-param>
</filter>
<filter-mapping>
<!--使用上面定义的filter过滤器拦截-->
<filter-name>filter</filter-name>
<!-- /* -> 拦截所有请求 -->
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>
然后再用自定义的UrlFilter类读取出设置的默认参数。
实现javax.servlet 中的Filter的接口
获取的结果:
通过字符窜的分割函数拿出多个值,然后就进行你的操作了。