您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
4_Filter_细节_web.xml配置方式
发布时间:2022-09-24 22:43:45编辑:雪饮阅读()
上篇了解了filter可以通过实现javax.servlet. Filter接口实现路由拦截处理放行等。
需要在实例类上用注解如WebFilter("*")。
那么其实不用WebFilter("*")注解也可以,但需要在WEB-INF下面建立web.xml(也可在创建项目时候勾选上面那个web application然后会有create web.xml可以勾选,一般javaee7对应的好像是3.x)
然后在web.xml通过filter标签来放置要指明的filter实例类,然后通过filter-mapping标签来指定filter标签里的实例对应的要拦截的url路由。
如:
<?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_3_1.xsd"
version="3.1">
<filter>
<filter-name>demo1</filter-name>
<filter-class>package3.Filter1</filter-class>
</filter>
<filter-mapping>
<filter-name>demo1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
其中这里filter标签里的filter-name标签如果你写完后会发现可能intelij idea会报红色提示,这个属于正常,只要在filter-mapping标签里面的filter-name标签中有对应filter标签里的filter-name标签名就不会报红色错误提示了。
关键字词:Filter,细节,web.xml,配置方式
相关文章
- 3_Filter_快速入门(类似php中常用的中间件)
- 25_案例_验证码_细节处理(removeAttribute)
- 20_会话技术_Session_细节2(session实例引用地址不同
- 19_会话技术_Session_细节1(用cookie来控制session关闭
- 08_会话技术_Cookie_细节4_Cookie共享
- 06_会话技术_Cookie_细节2_Cookie存活时间
- 05_会话技术_Cookie_细节1_发送多个Cookie
- phpunit如何生成代码覆盖率?“No filter is configured
- phpunit单文件测试的更细粒度filter
- phpunit中filter的使用(匹配命名空间、类、方法以及数