Servlet3.0新特性WebFilter(Annotation Filter)详解
摘要:
Servlet3.0作为J2EE 6规范一部分,并随J2EE6一起发布,WeFilter是过滤器注解,是Servlet3.0的新特性,不需要在web.xml进行配置,简化了配置。
|
Name |
Type |
Required |
Description |
|
filterName |
String |
Optional |
Name of the filter. |
|
value or urlPatterns |
String[] |
Required |
Specify one or more URL patterns to which the filter applies. Either of attribute can be used, but not both. |
|
dispatcherTypes |
DispatcherType[] |
Optional |
Specify types of dispatcher to which the filter applies. Default isjavax.servlet.DispatcherType.REQUEST |
|
servletNames |
String[] |
Optional |
Specify names of servlets to which the filter applies. |
|
displayName |
String |
Optional |
Display name of the filter. |
|
description |
String |
Optional |
Description of the filter. |
|
asyncSupported |
boolean |
Optional |
Specify whether the filter supports asynchronous operation mode. Default is false. |
|
initParams |
WebInitParam[] |
Optional |
Specify one or more initialization parameters of the filter. Each parameter is specified by@WebInitParamannotation type. |
|
smallIcon |
String |
Optional |
Specify name of the small icon of the filter. |
|
largeIcon |
String |
Optional |
Specify name of the large icon of the filter. |
OneFilter:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package com.what21.servlet.webfilter;import java.io.IOException;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.annotation.WebFilter;@WebFilter("/*")public class OneFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("OneFilter doFilter()"); chain.doFilter(request, response); } @Override public void destroy() { }} |
TwoFilter:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package com.what21.servlet.webfilter;import java.io.IOException;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.annotation.WebFilter;@WebFilter(servletNames = "MyFourServlet")public class TwoFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("TwoFilter doFilter()"); chain.doFilter(request, response); } @Override public void destroy() { }} |
ThreeFilter:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package com.what21.servlet.webfilter;import java.io.IOException;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.annotation.WebFilter;@WebFilter(servletNames = {"MyFourServlet", "MyFiveServlet"})public class ThreeFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("ThreeFilter doFilter()"); chain.doFilter(request, response); } @Override public void destroy() { }} |
FourFilter:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package com.what21.servlet.webfilter;import java.io.IOException;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.annotation.WebFilter;@WebFilter({"/one","/two"})public class FourFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("FourFilter doFilter()"); chain.doFilter(request, response); } @Override public void destroy() { }} |
FiveFilter:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.what21.servlet.webfilter;import java.io.IOException;import javax.servlet.DispatcherType;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.annotation.WebFilter;import javax.servlet.annotation.WebInitParam;@WebFilter( urlPatterns = "/five", filterName = "FiveFilter", initParams = { @WebInitParam(name = "name", value = "username"), @WebInitParam(name = "value", value = "password") }, description = "MyFiveFilter", dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD})public class FiveFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { String name = config.getInitParameter("name"); String value = config.getInitParameter("value"); System.out.println("name = " + name); System.out.println("value = " + value); System.out.println("init()....."); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("FiveFilter doFilter()"); } @Override public void destroy() { }} |
Servlet3.0新特性WebFilter(Annotation Filter)详解的更多相关文章
- 【servlet3.0新特性】Annotation注解配置
servlet3.0新特性Servlet3.0引入的若干重要新特性,包括异步处理.新增的注解支持.可插性支持等等,为读者顺利向新版本过渡扫清障碍.Servlet3.0新特性概述Servlet3.0作为 ...
- C#7.0新特性和语法糖详解
转自IT之家网--DotNet码农:https://www.ithome.com/html/win10/305148.htm 伴随Visual Studio 2017的发布,C#7.0开始正式走上工作 ...
- Java基础加强-(注解,动态代理,类加载器,servlet3.0新特性)
1. Annotation注解 1.1. Annotation概述 Annotation是JDK 5.0以后提供对元数据的支持,可以在编译.加载和运行时被读取,并执行相应的处理.所谓Annota ...
- Servlet3.0新特性
1 Servlet3.0新特性概述 使用要求:MyEclipse10.0或以上版本,发布到Tomcat7.0或以上版本,创建JavaEE6.0应用! Servlete3.0的主要新特性如下三部分: 使 ...
- 【Servlet3.0新特性】第03节_文件上传
这是一个Web Project 首先是web.xml <?xml version="1.0" encoding="UTF-8"?> <web- ...
- 使用Servlet3.0新特性asyncSupported=true时抛异常java.lang.IllegalStateException: Not supported
最近在运用Servlet3.0新特性:异步处理功能的时候出现以下了2个问题: 运行时会抛出以下两种异常: 一月 19, 2014 3:07:07 下午 org.apache.catalina.core ...
- Servlet3.0新特性(从注解配置到websocket编程)
Servlet3.0的出现是servlet史上最大的变革,其中的许多新特性大大的简化了web应用的开发,为广大劳苦的程序员减轻了压力,提高了web开发的效率.主要新特性有以下几个: 引入注解配置 支持 ...
- Servlet3.0新特性使用详解
可插拔的Web框架 几乎所有基于Java的web框架都建立在servlet之上.现今大多数web框架要么通过servlet.要么通过Web.xml插入.利用标注(Annotation)来定义servl ...
- Java自学手记——servlet3.0新特性
servlet3.0出来已经很久了,但市场上尚未普遍应用,servlet3.0有三个比较重要的新特性:使用注解来代替配置文件,异步处理以及上传组件支持. 支持servlet3.0的要求:MyEclip ...
随机推荐
- Alpha冲刺第5天
Alpha第六天 1.团队成员 郑西坤 031602542 (队长) 陈俊杰 031602504 陈顺兴 031602505 张胜男 031602540 廖钰萍 031602323 雷光游 03160 ...
- 使用Webdriver刷博客文章评论
package com.zhc.webdriver; import java.util.ArrayList; import java.util.Iterator; import java.util.c ...
- Android Handler 异步调用修改界面与主线程
在Android编程的过程中,如果在Activity中某个操作会运行比较长的时间,比如:下载文件.这个时候如果在主线程中直接下载文件,会造成Activity卡死的现象:而且如果时间超过5秒,会有ANR ...
- OneZero第四周第一次站立会议(2016.4.11)
1. 时间: 15:10--15:25 共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...
- Json序列化循环引用的问题
今天在发布接口的时候出突然出现了一个问题,报错代码为: 1 An exception has occurred while using the formatter 'JsonMediaTypeForm ...
- SpringBoot设置事务隔离等级
"If you're gonna play the game, boy, ya gotta learn to play it right" Spring Boot 使用事务非常简单 ...
- MT【87】迭代画图
评:此类题考场上就是取$n=1,2,3$找规律.
- 假装会python--爬取贴吧正文
贴吧的老历史想存下来,强行python爬取一波 队友太强,躺好别动,偶尔做点副业 假装会python 基本流程: 1.爬取页面,获取页面的html源码 2.分析源码 通过正则表达式 匹配到想要的内容 ...
- RabbitMQ的生产者和消费者
低级错误:启动程序的时候报错:socket close: 原因在配置文件中写的端口是:15672,应该是5672: client端通信口5672管理口15672server间内部通信口25672erl ...
- 使用 EXISTS 代替 IN 和 inner join
在使用Exists时,如果能正确使用,有时会提高查询速度: 1,使用Exists代替inner join 2,使用Exists代替 in 1,使用Exists代替inner join例子: 在一般写s ...