@WebFilter(servletNames="myFilter",urlPatterns = "/*") public class MyFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (servletRequest instanceof HttpServletRequest) { System.out.println(MessageFormat.format("請求路徑url=>{0}", ((HttpServletRequest) servletRequest).getRequestURI())); } filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { } }
@ServletComponentScan @SpringBootApplication public class QuickStartApplication { public static void main(String[] args) { SpringApplication.run(QuickStartApplication.class, args); } }
http://localhost:8080/getUser.do,後臺日誌輸出html
請求路徑url=>/getUser.do
name=>小王
java