当前位置:网站首页>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
边栏推荐
- Async void provoque l'écrasement du programme
- mysql 基本语句查询
- [51 single chip microcomputer traffic light simulation]
- 2020年最新字节跳动Android开发者常见面试题及详细解析
- Wu Enda's programming assignment - logistic regression with a neural network mindset
- 叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
- mui 关闭其他页面,只保留首页面
- decast id.var measure. Var data splitting and merging
- 超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
- 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?
猜你喜欢

Jupiter notebook installation

vscode小技巧

AUTOSAR from introduction to mastery 100 lectures (81) - FIM of AUTOSAR Foundation

【官宣】长沙软件人才实训基地成立!

SPI NAND flash summary

【微信小程序】flex布局使用记录

【快排】215. 数组中的第K个最大元素

内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘

叮~ 你的奖学金已到账!C认证企业奖学金名单出炉

nodejs + mysql 实现简单注册功能(小demo)
随机推荐
【官宣】长沙软件人才实训基地成立!
Nodejs + Mysql realize simple registration function (small demo)
JDBC connection pool
three.js文字模糊问题
web三大组件之Filter、Listener
Wu Enda's programming assignment - logistic regression with a neural network mindset
AUTOSAR from introduction to mastery 100 lectures (83) - bootloader self refresh
[51 single chip microcomputer traffic light simulation]
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
ECDSA signature verification principle and C language implementation
Free and open source charging pile Internet of things cloud platform
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
Conflict between Mui picker and drop-down refresh
Utils of various date conversion
Learning notes of AMBA protocol
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
PC starts multiple wechat at one time
Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
5道刁钻的Activity生命周期面试题,学完去吊打面试官!
STD:: shared of smart pointer_ ptr、std::unique_ ptr