当前位置:网站首页>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
边栏推荐
- April 10, 2022 -- take the first step with C -- use C from Net class library call method (not understood)
- 学习太极创客 — MQTT 第二章(八)ESP8266 MQTT 用户密码认证
- Huawei cloud onemeeting tells you that the whole scene meeting is held like this!
- 算力时代怎么「算」?「算网融合」先发优势很重要!
- 2837. The total number of teams
- 2022 t elevator repair test question bank simulation test platform operation
- 【Try to Hack】Cobalt Strike(一)
- 2022 welder (elementary) special operation certificate examination question bank and answers
- 蓝桥杯 历届试题 蚂蚁感冒
- 输入和输出实型数据
猜你喜欢
![[go language questions] go from 0 to entry 5: comprehensive review of map, conditional sentences and circular sentences](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 5: comprehensive review of map, conditional sentences and circular sentences

社招两年半10个公司28轮面试面经

Markdown Mermaid planting grass (1)_ Introduction to Mermaid

28 rounds of interviews with 10 companies in two and a half years

Software supply chain security risk guide for enterprise digitalization and it executives

还在付费下论文吗?快来跟我一起白piao知网

Leetcode week 299

Analysis of variance

Ali open source (easyexcel)

Jenkins pipeline's handling of job parameters
随机推荐
Flatten of cnn-lstm
How strong a mathematical foundation does deep learning need?
odoo15 Module operations are not possible at this time, please try again later or contact your syste
Visualization of neural network structure in different frames
internship:术语了解及着手写接口
Why does next() in iterator need to be forcibly converted?
bluecmsv1.6代码审计
input separator
Fix the simulator that cannot be selected by flutter once
社招两年半10个公司28轮面试面经
C#应用程序界面开发基础——窗体控制
JSP to get the value in the session
Racher add / delete node
修复一次flutter 无法选中模拟器
ThreadLocal原理
2788.Cifera
Lucene构建索引的原理及源代码分析
03.hello_ rust
Bluecmsv1.6 code audit
Can layoffs really save China's Internet?