设置跨域配置。打开<Geoserver>\webapps\geoserver\web.xml文件,找到文件中<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-name>cross-origin</filter-name>
-
<url-pattern>/*</url-pattern>
-
</filter-mapping>
-
...
重启geoserver服务,访问即可