openlayer3跨域问题解决方法

我用Geoserver发布的图层,里面遇到的跨域问题,具体解决方案如下。

1.把CORS文件里面的解压文件org放到D:\GeoServer 2.7.2\webapps\geoserver\WEB-INF\classes目下

2.修改D:\GeoServer 2.7.2\webapps\geoserver\WEB-INF\目录下的web.xml;如下:

在filter集合末尾额外添加一个filter:
 <filter>
      <filter-name>cross-origin</filter-name>
      
      <filter-class>org.mortbay.servlets.CrossOriginFilter</filter-class>
      <init-param>
        <param-name>allowedOrigins</param-name>
        <param-value>*</param-value>
      </init-param>
      <init-param>
       <param-name>allowedMethods</param-name>
       <param-value>GET,POST</param-value>
      </init-param>
      <init-param>
       <param-name>allowedHeaders</param-name>
       <param-value>x-requested-with,content-type</param-value>
      </init-param>
    </filter> 
在filter-mapping末尾额外添加一个filter-mapping
<filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

3.重启


转载自:https://blog.csdn.net/jsboy123/article/details/49383613

You may also like...