Java後臺處理ajax跨域請求處理

在配置中添加一個請求過濾器就能夠了。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() {}

  }

相關文章
相關標籤/搜索