本人亲测好用
- 报错信息如下图所示
- 复制geoserver目录下的lib的里的geoserver\lib找jetty-servlets-XX.jar , jetty-util-xx.jar(xx表示不同的版本)两个jar包,将其粘贴至geoserver\webapps\geoserver\WEB-INF\lib\目录下;
- 找到geoserver\webapps\geoserver\WEB-INF目录下找web.xml,把下面内容的注释去掉
Uncomment following filter to enable CORS in Jetty. Do not forget the second config block further down.
<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>
- 并追加如下代码
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.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>
- 添加对应的mapping标签
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>