어떻게 서버 로 하여 금 크로스 필드 를 지원 하 게 합 니까?

2172 단어 js
       ,      apache
(1)  http       :C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf
 LoadModule headers_module modules/mod_headers.so        .
(2)  Header set Access-Control-Allow-Origin *

    AllowOverride none
    Require all granted
         Header set Access-Control-Allow-Origin *

(3)  http  

   tomcat,  spring MVC  
       ,    :
Java        
package com.web.filter;  
  
import java.io.IOException;  
  
import javax.servlet.Filter;  
import javax.servlet.FilterChain;  
import javax.servlet.FilterConfig;  
import javax.servlet.ServletException;  
import javax.servlet.ServletRequest;  
import javax.servlet.ServletResponse;  
import javax.servlet.http.HttpServletResponse;  
  
import com.common.dict.Constant2;  
  
import oa.service.DictionaryParam;  
  
public class SimpleCORSFilter implements Filter{  
  
    @Override  
    public void destroy() {  
          
    }  
  
    @Override  
    public void doFilter(ServletRequest req, ServletResponse res,  
            FilterChain chain) throws IOException, ServletException {  
            HttpServletResponse response = (HttpServletResponse) res;  
            response.setHeader("Access-Control-Allow-Origin", DictionaryParam.get(Constant2.DICTIONARY_GROUP_GLOBAL_SETTING, "AccessControlAllowOrigin"));  
            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, res);  
          
    }  
  
    @Override  
    public void init(FilterConfig arg0) throws ServletException {  
          
    }  
  
}  
    :response.setHeader("Access-Control-Allow-Origin", "*");
 
  
      cors  
      com.web.filter.SimpleCORSFilter  
      
      
      cors  
      /*  
      
 
        ajax      .

좋은 웹페이지 즐겨찾기