In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to configure Filter filtering and blocking in SpringBoot. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. Complete the registration of Filter components by scanning comments
Create a class that implements the Filter interface and the doFilter () method
Use the annotation @ WebFilter in this class to set filterName and urlPatterns
Write code in doFilter
Write startup classes: add the annotation @ ServletComponentScan
/ * SpringBoot Integration Filter Project www.1b23.com * / @ WebFilter (filterName= "FirstFilter", urlPatterns= {"* .do", "* .jsp"}) @ WebFilter (filterName= "FirstFilter", urlPatterns= "/ first") public class FirstFilter implements Filter {@ Override public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException ServletException {System.out.println ("enter Filter") Chain.doFilter (request, response); System.out.println ("leave Filter");}} / / Project www.1b23.com@SpringBootApplication@ServletComponentScanpublic class App {public static void main (String [] args) {SpringApplication.run (App.class, args);}}
UrlPatterns is of array type and can intercept multiple urlPatterns= {".do", ".jsp"}
two。 Complete the registration of Filter components through the method
Create a class that implements the Filter interface and the doFilter () method
Write startup classes
Add a method that returns an object of FilterRegistrationBean, which can create an instance of the Filter object
Create a FilterRegistrationBean object and pass in the instantiated Filter object
Add Url,bean.addUrlPatterns ()
Returns the FilterRegistrationBean object
Add @ Bean to this method
/ * Register Filter project www.1b23.com * / @ Beanpublic FilterRegistrationBean getFilterRegistrationBean () {FilterRegistrationBean bean = new FilterRegistrationBean (new SecondFilter ()); / / bean.addUrlPatterns (new String [] {"* .do", "* .jsp"}); bean.addUrlPatterns ("/ second"); return bean } this is the end of how to configure Filter filtering and blocking in SpringBoot. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.