Article From:https://www.cnblogs.com/lvwqq/p/9071081.html

@Configuration
@Order(1)//The smaller the priority is, the higher the priority is

//filterName  Filter name urlPatterms address to filter
@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(“Initialize the address filter,, “,”);
}

@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(“String format —–> > > {} “, sendCharSet);
logger.info(“The prerequesting address is —–> > > {}, sendUrl + sendUrl_);
chain.doFilter(request, response);
}

@Override
public void destroy() {
// TODO Auto-generated method stub
logger.info(“Destroy address filter,, “);
}

}

Link of this Article: Spring-Cloud-Filter (filter)

Leave a Reply

Your email address will not be published. Required fields are marked *