当前位置:网站首页>Three web components (servlet, filter, listener)
Three web components (servlet, filter, listener)
2022-04-23 11:03:00 【yueseck】
Catalog
4.3 Filter configuration details
One 、Servlet
Click here to introduce the past servlet
Two 、Filter
1. Concept
* Filters in life : Water purifier , air cleaner , bandit 、
* web Filter in : When accessing the server's resources , Filters can intercept requests , Complete some special functions .
* The function of the filter :
* Generally used to complete general operations . Such as : validate logon 、 Unified coding 、 Sensitive character filtering ...
2. step
1. Define a class , Implementation interface Filter
2. Replication method
3. Configure interception path
1. web.xml
2. annotation
3. Code
@WebFilter("/*")// Before accessing all resources , Will execute the filter
public class FilterDemo1 implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
System.out.println("filterDemo1 Carried out ....");
// release
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {
}
}
4. Filter details
4.1web.xml To configure
<filter>
<filter-name>demo1</filter-name>
<filter-class>cn.itcast.web.filter.FilterDemo1</filter-class>
</filter>
<filter-mapping>
<filter-name>demo1</filter-name>
<!-- Intercept path -->
<url-pattern>/*</url-pattern>
</filter-mapping>
4.2 Filter execution process
1. Perform filter
2. Resources after implementation of release
3. Come back and execute the code below the filter release code
4.3 Filter configuration details
* Intercept path configuration :
1. Specific resource paths : /index.jsp Only visit index.jsp Resource time , The filter will be executed
2. Intercept Directory : /user/* visit /user All resources under , Filters are executed
3. Suffix blocking : *.jsp Access all suffixes named jsp Resource time , Filters are executed
4. Intercept all resources :/* When accessing all resources , Filters are executed
* Interception mode configuration : How resources are accessed
* Annotation configuration :
* Set up dispatcherTypes attribute
1. REQUEST: The default value is . Browser requests resources directly
2. FORWARD: Forward access to resources
3. INCLUDE: Contains access to resources
4. ERROR: Wrong jump resource
5. ASYNC: Asynchronous access to resources
* web.xml To configure
* Set up <dispatcher></dispatcher> Labels can be
5. Filter chain
* Execution order : If there are two filters : filter 1 And filters 2
1. filter 1
2. filter 2
3. Resource execution
4. filter 2
5. filter 1
* The filter sequence problem :
1. Annotation configuration : Compare according to the string comparison rules of class names , If it's worth less, execute it first
* Such as : AFilter and BFilter,AFilter Just do it first .
2. web.xml To configure : <filter-mapping> Who is defined above , Who will execute first
3、 ... and 、Listener
* Concept :web One of the three components of .
* Event monitoring mechanism
* event : One more thing
* Event source : Where it happened
* Monitor : An object
* Register to listen : Put the event 、 Event source 、 Listeners are bound together . When an event occurs on the event source , Execute listener code
* ServletContextListener: monitor ServletContext Object creation and destruction
* Method :
* void contextDestroyed(ServletContextEvent sce) :ServletContext The method is called before the object is destroyed
* void contextInitialized(ServletContextEvent sce) :ServletContext The method is called after the object is created
* step :
1. Define a class , Realization ServletContextListener Interface
2. Replication method
3. To configure
1. web.xml
<listener>
<listener-class>cn.itcast.web.listener.ContextLoaderListener</listener-class>
* Specify initialization parameters <context-param>
2. annotation :
* @WebListener
版权声明
本文为[yueseck]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231053377300.html
边栏推荐
- 高价买来的课程,公开了!phper资料分享
- How to quickly download vscode
- Latex usage
- 语雀文档编辑器将开源:始于但不止于Markdown
- Is the pointer symbol of C language close to variable type or variable name?
- Pytorch implementation of transformer
- 学习 Go 语言 0x01:从官网开始
- Pycharm
- Kaggle - real battle of house price prediction
- How to bind a process to a specified CPU
猜你喜欢
CUMCM 2021-B:乙醇偶合制备C4烯烃(2)
Visual common drawing (V) scatter diagram
Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition
第六站神京门户-------手机号码的转换
GO接口使用
Visual solutions to common problems (VIII) mathematical formulas
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
Mysql8. 0 installation guide
Excel·VBA数组冒泡排序函数
Let the LAN group use the remote device
随机推荐
MySQL面试题讲解之如何设置Hash索引
语雀文档编辑器将开源:始于但不止于Markdown
Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
Database management software sqlpro for SQLite for Mac 2022.30
Typora operation skill description (I)
第六站神京门户-------手机号码的转换
Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities
VScode
解决方案架构师的小锦囊 - 架构图的 5 种类型
Leetcode22: bracket generation
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
Visual Road (XII) detailed explanation of collection class
Learning Notes 6 - Summary of several deep learning convolutional neural networks
Qinglong panel pull library command update [April 20, 2022] collection is not lost
GO接口使用
Mba-day6 logic - hypothetical reasoning exercises
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
Understand the key points of complement
web三大组件(Servlet,Filter,Listener)