基于CORS的geoserver同源访问策略
这个问题理顺整个2天。终于攻克。记录下来。
1.下载文件
首先下载cors压缩包,解压,得到的是org/mortbay/servlets/CrossOriginFilter.class文件,把此文件拷贝到安装文件夹下的WEB-INF/CLASS文件夹中。在我电脑上的路径为:C:\Program Files (x86)\GeoServer 2.7.0\webapps\geoserver\WEB-INF\classes\org\mortbay\servlets\CrossOriginFilter.class.
2.改动geoserver配置文件
2.1 打开geoserver安装文件夹下的web.xml文件,我的电脑上路径为:C:\Program Files (x86)\GeoServer 2.7.0\webapps\geoserver\WEB-INF\web.xml
2.2 在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-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>
2.3 在filter-mapping末尾额外加入一个filter-mapping
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>