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 ...
随机推荐
- Ubuntu读取/root/.profile时发现错误:mesg:ttyname fa
https://jingyan.baidu.com/article/fb48e8be3743696e632e1450.html gedit /root/.profile mesg n => tt ...
- Citrix Merchandising Server 配置
获取Citrix Merchandising Server虚拟镜像: 我们可以从Citrix官网上下载Citrix Merchandising Server(分为XenServer和vSphere), ...
- 2017全球GDP总量达74万亿美元 各国占比排行榜
全球GDP总量达74万亿美元 各国占比排行榜 2017年公布的2015年全球各国GDP占比,数据图片来源:世界银行报告 2月24日,来自世界银行的最新GDP数字已于2月早些时候公布,现由How ...
- [日常工作] 并行计算引发Microsoft.jscript.ni.dll的内存溢出问题的分析解决. .net framework 的版本说明
1. 性能组进行 单点性能测试时发现 商务智能的 并行分析有问题. 效率很低, 开发人员查看iis 的日志 发现错误原因是 Microsoft.jscript.ni.dll 有内存溢出的问题 开发人员 ...
- JVM学习笔记(三):类文件结构
代码编译的结果从本地机器码转变为字节码,是存储格式发展的一小步,却是编程语言发展的一大步. 实现语言无关性的基础是虚拟机和字节码存储格式.Java虚拟机不和包括Java在内的任何语言绑定,只与&quo ...
- js中的async await
JavaScript 中的 async/await 是属于比较新的知识,在ES7中被提案在列,然而我们强大的babel粑粑已经对它进行列支持! 如果开发中使用了babel转码,那么就放心大胆的用吧. ...
- Queries about less or equal elements CodeForces - 600B(二分)
You are given two arrays of integers a and b. For each element of the second arraybj you should find ...
- BZOJ1492 货币兑换 CDQ分治优化DP
1492: [NOI2007]货币兑换Cash Time Limit: 5 Sec Memory Limit: 64 MB Description 小Y最近在一家金券交易所工作.该金券交易所只发行交 ...
- Lua 调试库
Lua 调试库 http://blog.csdn.net/vermilliontear/article/details/50851045 http://blog.csdn.net/vermillion ...
- MT【77】函数的定义理解
答案:D.比如C 中令$x^2+1=2,x=-1,1,$ 得$f(2)=0,2$与定义矛盾,A,B同理排除. D中注意到$x^2-2x$与$|x-1|$对称轴都是$x=1$. 评:函数的定义,首先是两 ...