geoserver跨域设置2.15.0版本

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-httpjetty-util jar包,放在lib目录,再次重启即可

阅读 985

推荐阅读