在配置中添加一個請求過濾器就能夠了。it
public class SimpleCORSFilter implements Filter {io
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,ast
ServletException {class
HttpServletResponse response = (HttpServletResponse) res;配置
response.setHeader("Access-Control-Allow-Origin", "*");請求
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");im
response.setHeader("Access-Control-Max-Age", "3600");filter
response.setHeader(di
"Access-Control-Allow-Headers",360
"Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With");
chain.doFilter(req, res);
}
public void init(FilterConfig filterConfig) {}
public void destroy() {}
}