@WebFilter(urlPatterns = "/*", filterName = "corsFilter") public class CorsFilter implements Filter { @Override public void destroy() { } @Override public void doFilter(ServletRequest req, ServletResponse rep, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) rep; response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); chain.doFilter(req, response); } @Override public void init(FilterConfig arg0) throws ServletException { } }
原文地址:https://www.cnblogs.com/wujf/p/8384010.html
时间: 2024-10-28 20:41:00