geoserver中的跨域解决方案

此解决方案针对在tomcat下通过geoserver.war包部署的方法。

第一步

下载cors-filter-2.6.jar、java-property-utils-1.13.jar两个文件,放到.\geoserver\WEB-INF\lib目录下.
这两文件,可以去:https://search.maven.org/search 自己搜

第二步

修改web.xml文件,web.xml位于./geoserver/WEB-INF目录下。打开文件,在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>/*  
    

如上操作后,重启tomcat服务,OK!

你可能感兴趣的:(Geoserver)