Geoserver WFS跨域设置

admin0条评论 373 次浏览

(1)测试版本为geoserver2.10.1(windows安装版本.exe)。

(2)测试版本为geoserver2.13.0(tomcat压缩包.war)。

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

第一种:(windows安装版本.exe)

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

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

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

<!–
允许跨域相关设置
–>
<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>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>FlushSafeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>SessionDebugger</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>GZIP Compression Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>Request Logging Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

 

第二种:(tomcat压缩包.war)

下载cors-filter-1.7.jar,Java-property-utils-1.9.jar这两个库文件,放到C:\apache-tomcat-7.0.85\webapps\geoserver\WEB-INF\lib目录下

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

打开C:\apache-tomcat-7.0.85\webapps\geoserver\WEB-INF\web.xml文件,在filter集合末尾额外添加如下配置:

<filter>         
    <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>  
  
<filter-mapping>  
    <filter-name>CORS</filter-name>  
    <url-pattern>/*</url-pattern>  
</filter-mapping>