美文网首页
tomcat下部署geoserver解决跨域访问问题

tomcat下部署geoserver解决跨域访问问题

作者: 嘀灬学生卡 | 来源:发表于2019-05-31 11:05 被阅读0次

openlaryes调用geoserver的WFS服务,出现错误:No 'Access-Control-Allow-Origin' header is present on the requested resource.

网上查找说将geoserver部署到tomcat之后,打开tomcat下webapps\geoserver\WEB-INF目录下的web.xml文件,添加一下内容,重启tomcat即可。

<filter>  
    <filter-name>CorsFilter</filter-name>  
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>  
</filter>  
<filter-mapping>  
    <filter-name>CorsFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
</filter-mapping>

但试了n遍没卵用,不知道为什么,最后配置如下倒是成功了。

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
        <param-name>cors.allowed.origins</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.headers</param-name>
        <param-value>Content-Type,X-Requested-With,Accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
    </init-param>
</filter>

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

相关文章

网友评论

      本文标题:tomcat下部署geoserver解决跨域访问问题

      本文链接:https://www.haomeiwen.com/subject/hjcwtctx.html