spring boot项目配置跨域(拦截器)

/**
* 跨域配置
*/
@WebFilter(urlPatterns = {"/*"})
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest servletRequest = (HttpServletRequest) request;
HttpServletResponse servletResponse = (HttpServletResponse) response;
servletResponse.setHeader("Access-Control-Allow-Origin", servletRequest.getHeader("Origin"));
servletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
servletResponse.setHeader("Access-Control-Max-Age", "3600");
servletResponse.setHeader("Access-Control-Allow-Headers", "TOKEN, Origin, X-Requested-With, Content-Type, Accept,Content-Disposition");
servletResponse.addHeader("Access-Control-Allow-Credentials", "true");
chain.doFilter(request, response);
}
}

spring boot项目配置跨域(拦截器)

上一篇:springboot2.1.3配置sftp,自定义sftp连接池(转)


下一篇:javaScript 中的闭包