当前位置:网站首页>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
边栏推荐
- Analysis of the latest Android high frequency interview questions in 2020 (BAT TMD JD Xiaomi)
- ESP32 VHCI架构传统蓝牙设置scan mode,让设备能被搜索到
- Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
- mui picker和下拉刷新冲突问题
- Free and open source intelligent charging pile SaaS cloud platform of Internet of things
- R语言中dcast 和 melt的使用 简单易懂
- 叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
- 100 GIS practical application cases (52) - how to keep the number of rows and columns consistent and aligned when cutting grids with grids in ArcGIS?
- 十万大学生都已成为猿粉,你还在等什么?
- Translation of attention in natural language processing
猜你喜欢
The project file '' has been renamed or is no longer in the solution, and the source control provider associated with the solution could not be found - two engineering problems
web三大组件之Servlet
9419页最新一线互联网Android面试题解析大全
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
AUTOSAR from introduction to mastery 100 lectures (51) - AUTOSAR network management
Important knowledge of network layer (interview, reexamination, term end)
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
LeetCode_DFS_中等_695.岛屿的最大面积
X509 parsing
随机推荐
Utils of various date conversion
MySQL 8.0.11下载、安装和使用可视化工具连接教程
Mui + hbuilder + h5api simulate pop-up payment style
Start mqbroker CMD failure resolution
Office 2021 installation package download and activation tutorial
Brief introduction of asynchronous encapsulation interface request based on uniapp
5 tricky activity life cycle interview questions. After learning, go and hang the interviewer!
超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
Subscribe to Alibaba demo send business messages
web三大组件之Servlet
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
FatFs FAT32 learning notes
Jupiter notebook installation
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
nodejs + mysql 实现简单注册功能(小demo)
ECDSA signature verification principle and C language implementation
MySQL5.5安装教程
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
Customize classloader and implement hot deployment - use loadclass
Async void provoque l'écrasement du programme