geoserver 默认不开启跨域设置,开启步骤如下:
1、修改配置文件 web.xml
\webapps\geoserver\WEB-INF\web.xml
搜索:cross-origin,将注释的部分解注。
<!-- Uncomment following filter to enable CORS -->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>chainPreflight</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<!-- Uncomment following filter to enable CORS -->
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、下载 jetty-servlets jar 包,2.15.0 对应的版本是 jetty-servlets-9.4.12.v20180830.jar, 放在
\geoserver\WEB-INF\lib
3、重启 geoserver, 如果报错,再下载对应 jetty-http 和 jetty-util jar 包,放在 lib 目录,再次重启即可