当前位置:网站首页>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
边栏推荐
- PC starts multiple wechat at one time
- Go language: passing slices between functions
- Translation of attention in natural language processing
- 缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
- 4.22 study record (you only did water problems in one day, didn't you)
- mysql 基本语句查询
- (personal) sorting out system vulnerabilities after recent project development
- Request和Response及其ServletContext总结
- 「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
- 5道刁钻的Activity生命周期面试题,学完去吊打面试官!
猜你喜欢
【微信小程序】flex布局使用记录
100 GIS practical application cases (51) - a method for calculating the hourly spatial average of NC files according to the specified range in ArcGIS
Mui + hbuilder + h5api simulate pop-up payment style
JMeter operation redis
Customize classloader and implement hot deployment - use loadclass
Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
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
Nodejs + websocket cycle small case
Learning materials
MySQL —— 16、索引的数据结构
随机推荐
uniapp image 引入本地图片不显示
web三大组件之Servlet
mysql 基本语句查询
Hbuilderx + uniapp packaging IPA submission app store stepping on the pit
Pyqt5 store opencv pictures into the built-in sqllite database and query
STM32 tracking based on open MV
mui picker和下拉刷新冲突问题
Mui + hbuilder + h5api simulate pop-up payment style
4.22 study record (you only did water problems in one day, didn't you)
MySQL —— 16、索引的数据结构
STD:: shared of smart pointer_ ptr、std::unique_ ptr
Record Alibaba cloud server mining program processing
ECDSA signature verification principle and C language implementation
AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
SQL exercise question 1
Use of Presto date function
decast id.var measure.var数据拆分与合并
100 lectures on practical application cases of Excel (VIII) - report connection function of Excel
Scons build embedded ARM compiler
Async void provoque l'écrasement du programme