欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Spring-Cloud-Filter(过滤器)

程序员文章站 2024-03-31 08:08:16
@Configuration@Order(1)//设置优先级值越小优先级越高 //filterName 过滤器名称 urlPatterms 要过滤的地址@WebFilter(filterName="urlfilter",urlPatterns="/*")public class UrlFilter ......

@Configuration
@Order(1)//设置优先级值越小优先级越高

//filterName  过滤器名称  urlPatterms 要过滤的地址
@WebFilter(filterName="urlfilter",urlPatterns="/*")
public class UrlFilter implements Filter {
private Logger logger = org.slf4j.LoggerFactory.getLogger(UrlFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
logger.info("初始化地址过滤器,,,");
}

@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String sendCharSet = httpServletRequest.getCharacterEncoding();
String sendUrl = httpServletRequest.getRequestURI();
String sendUrl_ =httpServletRequest.getQueryString();
logger.info("字符串格式----->>>{}",sendCharSet);
logger.info("前置请求地址----->>>{}",sendUrl + sendUrl_);
chain.doFilter(request, response);
}

@Override
public void destroy() {
// TODO Auto-generated method stub
logger.info("销毁地址过滤器,,,");
}

}