当前位置:网站首页>Filter and listener of three web components
Filter and listener of three web components
2022-04-23 13:11:00 【ArchieSean】
The blogger's name is taken from 《 Shaun the Sheep 》 Shawn the lamb in the , The name is : Sean , Transliterated as Sean, Take your own last name : Archie , In order to conform to our reading habits , Connected to form ArchieSean. The blogger is currently a junior reading , Aiming to build blog into a technical stack of personal online notes , Be convenient for yourself and others . If there are any mistakes in the blog , Please point out , Thank you. .
Filter、Listener、Servlet Collectively referred to as web Three components . This article only covers the first two , about servlet We will open another article to introduce in detail . about Listener Just to understand .
List of articles
Filter
Concept
web filter : When the browser accesses resources , The filter intercepts the browser's request , Used to complete some special functions .
effect : It is generally used for some general operations . for example : validate logon 、 Unified coding processing, etc .
Basic use
Filter Three steps for using :
- Create a class implementation Filter Interface
- Replication method
- Configure interception path ( Two configurations xml And annotation configuration )
Related configuration
Configure interception path :
The way 1:xml To configure
Written before servlet When , use xml The configuration has such a paragraph xml To configure :
<servlet>
<servlet-name> name </servlet-name>
<servlet-class> Full class name </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> name </servlet-name>
<url-pattern> Access directory </url-pattern>
</servlet-mapping>
and filter Of xml To configure , Exactly the same as this :
<filter>
<filter-name> name </filter-name>
<filter-class> Full class name </filter-class>
</filter>
<filter-mapping>
<filter-name> name </filter-name>
<url-pattern>/*</url-pattern> <!-- The path here is not an access path , But the setting of the intercepted path ,/* Means intercept all --> </filter-mapping>
The way 2: Annotation configuration
@webFilter(" Intercept path ")
Interception process
filter During the intercept , Order as follows :
- Execute interceptor
- Resources after implementation of release
- Execute the code below the release statement
Life cycle
- init: After the server starts , Will create filter object , call init Method . Only once , Used to load resources .
- doFilter: Every time a blocked resource is requested , This method will be implemented .
- destory: After the server is shut down ,filter Object destroyed . The server is shut down normally , This method executes once . Used to free resources .
Filter chain
If there are multiple filters , The order of execution is :
for example : There are three filters , The order of execution is as follows :
- filter 1
- filter 2
- filter 3
- Resource execution
- filter 3
- filter 2
- filter 1
For the filter priority problem :
- Annotation configuration :
Compare according to the string of class name , Small first . - xml To configure :
<filter-mapping></fliter-mapping>
Sequential execution ( From top to bottom )
Listener
Concept
Three elements of event monitoring mechanism : event , Event source , Monitor
In a nutshell , Is to bind the three elements together , When the event triggers , Execute the contents of the listener .
Basic use
- Define a class , Realization ServletContextListener Interface
- Replication method
- To configure
3.1 web.xml:
<listener>
<listener-class> Full class name </listener-class>
</listener>
3.2 Annotation configuration @WebListener
filter and Listeber That's it , If there are any questions , Commentable , It will be corrected immediately .
版权声明
本文为[ArchieSean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231306323021.html
边栏推荐
- Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
- 缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
- Proteus 8.10 installation problem (personal test is stable and does not flash back!)
- Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
- Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
- 鸿蒙系统是抄袭?还是未来?3分钟听完就懂的专业讲解
- nodejs + mysql 实现简单注册功能(小demo)
- 解决虚拟机中Oracle每次要设置ip的问题
- jmeter操作redis
- Hbuilderx + uniapp packaging IPA submission app store stepping on the pit
猜你喜欢
100 GIS practical application cases (51) - a method for calculating the hourly spatial average of NC files according to the specified range in ArcGIS
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
Analysis of the latest Android high frequency interview questions in 2020 (BAT TMD JD Xiaomi)
SPI NAND flash summary
Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘
【动态规划】221. 最大正方形
【快排】215. 数组中的第K个最大元素
Learning notes of AMBA protocol
PC starts multiple wechat at one time
[untitled] make a 0-99 counter, P1 7 connected to key, P2 connected to nixie tube section, common anode nixie tube, P3 0,P3. 1. Connect the nixie tube bit code. Each time you press the key, the nixie
随机推荐
【行走的笔记】
async void 导致程序崩溃
melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
Community version Alibaba MQ ordinary message sending subscription demo
AUTOSAR from introduction to mastery 100 lectures (87) - key weapon of advanced EEA - AUTOSAR and DDS
The filter() traverses the array, which is extremely friendly
[51 single chip microcomputer traffic light simulation]
vscode小技巧
HQL statement tuning
Mui + hbuilder + h5api simulate pop-up payment style
Data warehouse - what is OLAP
MySQL -- 16. Data structure of index
(1) Openjuterpyrab comparison scheme
async void 導致程序崩潰
将opencv 图片转换为字节的方式
ECDSA signature verification principle and C language implementation
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
SQL exercise question 1
mui picker和下拉刷新冲突问题
FFmpeg常用命令