当前位置:网站首页>2. integrate filter
2. integrate filter
2022-06-28 20:23:00 【Yuyy】
- Complete with annotation scan Filter Registration of components
- stay servlet3.0 after , We can use annotations @WebFilter To configure the filter , No need to filter in this way xml The configuration in the file can be used , But the default filter order is controlled by class name , If there are strict requirements for filter sequence , You need to in web.xml In the definition of ( In order of precedence ).
- 1.1 To write Filter /***SpringBoot Integrate Filter Mode one
<filter>
<filter-name>FirstFilter</filter-name>
<filter-class>com.bjsxt.filter.FirstFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>FirstFilter</filter-name>
<url-pattern>/first</url-pattern>
</filter-mapping>//@WebFilter(filterName="FirstFilter",urlPatterns={"*.do","*.jsp"})
@WebFilter(filterName="FirstFilter",urlPatterns="/first")
public class FirstFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
System.out.println(" Get into Filter");
arg2.doFilter(arg0, arg1);
System.out.println(" Leave Filter");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}/***SpringBoot Integrate Filter Mode one **/
@SpringBootApplication @ServletComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}- To complete by means of Filter Registration of components
- 2.1 To write Filter
/***SpringBoot Integrate Filter Mode two **/
public class SecondFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
System.out.println(" Get into SecondFilter");
arg2.doFilter(arg0, arg1);
System.out.println(" Leave SecondFilter");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
/*** SpringBoot Integrate Filter Mode two ***/
@SpringBootApplication
public class App2 {
public static void main(String[] args) {
SpringApplication.run(App2.class, args);
}
/*** register Servlet * @return */
@Bean
public ServletRegistrationBean getServletRegistrationBean(){
ServletRegistrationBean bean = new ServletRegistrationBean(new SecondServlet());
bean.addUrlMappings("/second");
return bean;
}
/*** register Filter */
@Bean
public FilterRegistrationBean getFilterRegistrationBean(){
FilterRegistrationBean bean = new FilterRegistrationBean(new SecondFilter());
//bean.addUrlPatterns(new String[]{"*.do","*.jsp"});
bean.addUrlPatterns("/second");
return bean;
}
}Post Views: 377
边栏推荐
- 输入和输出实型数据
- 裁员真能拯救中国互联网?
- 大智慧上怎么进行开户啊, 安全吗
- Windows 64 bit download install my SQL
- Why does next() in iterator need to be forcibly converted?
- SQL server2019 create a new SQL server authentication user name and log in
- 算力时代怎么「算」?「算网融合」先发优势很重要!
- Comparisonchain file name sort
- Compression and decompression commands
- Keyword long
猜你喜欢

Shell reads the value of the JSON file

ArrayList of collection

【学习笔记】主成分分析法介绍

电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!...
![[algorithm] I brushed two big factory interview questions and learned array again with tears in my eyes“](/img/13/1b49326d5fe79ed1e73a2b52e7c42f.png)
[algorithm] I brushed two big factory interview questions and learned array again with tears in my eyes“

rsync远程同步

CSDN salary increase technology selenium automated test stack summary

RT-Thread线程同步与线程通信

2022年P气瓶充装考试练习题及在线模拟考试

【Try to Hack】Cobalt Strike(一)
随机推荐
2022 P cylinder filling test exercises and online simulation test
新形势下的SaaS销售升级|ToB大师课
ThreadLocal principle
怎么理解云原生数据库的易用性?
Visualization of neural network structure in different frames
Employee salary management system
Day88. qiniu cloud: upload house source pictures and user avatars
5g NR MBS architecture introduction
Ali open source (easyexcel)
市值1200亿美金,老牌财税巨头Intuit是如何做到的?
Can layoffs really save China's Internet?
ROS中quaternion四元數和歐拉角轉換
如何做好客户成功的底层设计|ToB大师课
输入和输出字符型数据
Markdown Mermaid Grass (1) Introduction à Mermaid
Leetcode 36. 有效的数独(可以,一次过)
TcWind 模式设定
A few lines of code can realize complex excel import and export. This tool class is really powerful!
应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
Win 10 create a gin framework project