Geoserver WFS跨域设置

Geoserver WFS跨域设置

测试版本为geoserver2.11.0。

两种方法都可以实现跨域设置:

第一种:

下载跨域jar包jetty-servlets.jar(下载geoserver使用的对应jetty版本——可以查看<Geoserver>\lib下jetty-servlet.jar的版本作为对照)并将jar包放到<Geoserver>\webapps\geoserver\WEB-INF\lib文件夹下。

下载地址:http://central.maven.org/maven2/org/eclipse/jetty/jetty-servlets/

打开<Geoserver>\webapps\geoserver\web.xml文件,找到文件中<filter>平级的位置,添加如下内容:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<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>

找到文件中<filter-mapping>平级的位置,添加如下内容:

1

2

3

4

<filter-mapping

   <filter-name>cross-origin</filter-name

   <url-pattern>/*</url-pattern

</filter-mapping>

第二种:

下载cors-filter-1.7.jar,Java-property-utils-1.9.jar这两个库文件,放到<Geoserver>\webapps\geoserver\WEB-INF\lib目录下

下载地址:http://files.cnblogs.com/files/ytwy/jar.rar

打开<Geoserver>\webapps\geoserver\web.xml文件,找到文件中<filter>平级的位置,添加如下内容:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<filter-name>CORS</filter-name

  <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class

  <init-param

   <param-name>cors.allowOrigin</param-name

      <param-value>*</param-value

  </init-param

  <init-param

   <param-name>cors.supportedMethods</param-name

      <param-value>GET, POST, HEAD, PUT, DELETE</param-value

  </init-param

  <init-param

   <param-name>cors.supportedHeaders</param-name

      <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value

  </init-param

  <init-param

      <param-name>cors.exposedHeaders</param-name

      <param-value>Set-Cookie</param-value

  </init-param

  <init-param

      <param-name>cors.supportsCredentials</param-name

      <param-value>true</param-value

  </init-param

找到文件中<filter-mapping>平级的位置,添加如下内容:

1

2

3

4

<filter-mapping

    <filter-name>CORS</filter-name

    <url-pattern>/*</url-pattern

</filter-mapping>

  

转载自:https://blog.csdn.net/shishi521/article/details/88894937

You may also like...