码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc支持跨域请求

时间:2018-01-30 16:46:23      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:post   throws   mvc   config   override   nbsp   请求   pat   lte   

@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 {
    }

}

 

spring mvc支持跨域请求

标签:post   throws   mvc   config   override   nbsp   请求   pat   lte   

原文地址:https://www.cnblogs.com/wujf/p/8384010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!