跨域访问(cors) access-control-allow-origin 多个域名

1.首先要了解问什么访问要跨域
2.配置多个作用访问

资源文件中修改app.allowOrigin = http:XXX,HTTP:kkk,..
或者app.allowOrigin = * 这种相对来说风险极大


    public void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse, FilterChain filterChain)
                    throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpSession session = request.getSession();

        if ("true".equals(PropertiesUtils.getProperty("app.debug"))) {
            // 允许跨域访问
            response.setHeader("Access-Control-Allow-Origin",
                    PropertiesUtils.getProperty("app.allowOrigin"));
            response.setHeader("Access-Control-Allow-Headers",
                    "Origin, X-Requested-With, Content-Type, Accept, Cookie");
            response.setHeader("Access-Control-Allow-Methods",
                    "GET, POST, PUT, DELETE, OPTIONS");
            response.setHeader("Access-Control-Allow-Credentials", "true");
        }
    }

你可能感兴趣的:(跨域访问(cors) access-control-allow-origin 多个域名)