当前位置:网站首页>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
边栏推荐
- 2022茶艺师(中级)考试模拟100题及模拟考试
- 各种类型长
- Racher add / delete node
- 数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
- 新形势下的SaaS销售升级|ToB大师课
- Jenkins pipeline's handling of job parameters
- Are you still paying for your thesis? Come and join me
- 修复一次flutter 无法选中模拟器
- Use of WC command
- April 10, 2022 -- take the first step with C -- use C from Net class library call method (not understood)
猜你喜欢

rsync远程同步

Markdown mermaid種草(1)_ mermaid簡介

数据资产为王,如何解析企业数字化转型与数据资产管理的关系?

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

Are you still paying for your thesis? Come and join me

Markdown Mermaid Grass (1) Introduction à Mermaid

SQL server2019 create a new SQL server authentication user name and log in

Leetcode 36. 有效的数独(可以,一次过)

学习太极创客 — MQTT 第二章(八)ESP8266 MQTT 用户密码认证

不同框架的绘制神经网络结构可视化
随机推荐
数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
核芯物联蓝牙aoa定位系统服务器配置估算
Lecture 30 linear algebra Lecture 4 linear equations
How to analyze the relationship between enterprise digital transformation and data asset management?
输入分隔符
修复一次flutter 无法选中模拟器
Windows 64 bit download install my SQL
怎么理解云原生数据库的易用性?
【学习笔记】聚类分析
国产数据库名录一览
输入和输出实型数据
Jenkins pipeline's handling of job parameters
2342
2022焊工(初级)特种作业证考试题库及答案
2. 整合 Filter
C # application interface development foundation - form control
管道 | 与重定向 >
ref属性,props配置,mixin混入,插件,scoped样式
2022年T电梯修理考试题库模拟考试平台操作
ArrayList of collection