当前位置:网站首页>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
边栏推荐
- Summary of JVM knowledge points - continuously updated
- [untitled] PID control TT encoder motor
- 2021年6月程序员工资统计,平均15052元,你拖后腿了吗?
- 100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
- Imx6ull QEMU bare metal tutorial 2: usdhc SD card
- Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
- FatFs FAT32 learning notes
- (personal) sorting out system vulnerabilities after recent project development
- [51 single chip microcomputer traffic light simulation]
- Office 2021 installation package download and activation tutorial
猜你喜欢
叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
普通大学生如何拿到大厂offer?敖丙教你一招致胜!
[untitled] PID control TT encoder motor
9419页最新一线互联网Android面试题解析大全
缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
[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
filter()遍历Array异常友好
初鉴canvas,展示个小小的小案例
Hbuilderx + uniapp packaging IPA submission app store stepping on the pit
随机推荐
Ffmpeg common commands
office2021安装包下载与激活教程
Data warehouse - what is OLAP
9419 page analysis of the latest first-line Internet Android interview questions
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
GIS practical tips (III) - how to add legend in CASS?
CMSIS cm3 source code annotation
Community version Alibaba MQ ordinary message sending subscription demo
mysql 基本语句查询
The first lesson is canvas, showing a small case
4.22 study record (you only did water problems in one day, didn't you)
STD:: shared of smart pointer_ ptr、std::unique_ ptr
FFmpeg常用命令
AUTOSAR from introduction to mastery 100 lectures (83) - bootloader self refresh
Custom nail robot alarm
uniapp image 引入本地图片不显示
mui + hbuilder + h5api模拟弹出支付样式
「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
(1) Openjuterpyrab comparison scheme
4.22学习记录(你一天只做了水题是吗)