geoserver2.13.2的跨域问题


geoserver2.13.2的跨域问题
第一步:
/usr/tomcat/webapps/geoserver/WEB-INF/lib 添加三个jar文件
jetty-servlet-9.2.13.v20150730.jar
jetty-servlets-9.2.13.v20150730.jar
jetty-util-9.2.13.v20150730.jar
下载windows版本的geoserver2.13.2的安装目录D:\geoserver\lib中拷进来
下载地址:
http://geoserver.org/release/2.13.2/
https://download.csdn.net/download/lu_yuexin/10594827

第二步:
/usr/tomcat/webapps/geoserver/WEB-INF/web.xml添加如下

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>

  <!--关键部位1,cors.allowed.origins的值
    1.若需进行用户密码验证,则其值不可为“*”,可为需进行跨域的应用域名端口的链接(如下所示),因为为“*”的该项与下面的cors.support.credentials不可同时存在,否则tomcat启动会出错。
    2.若无序进行用户名密码验证,则其值可为“*”。若为“*”,则下面的cors.support.credentials项要删除。
 -->
  <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,Authorization</param-value>
  </init-param>
  <init-param>
    <param-name>cors.exposed.headers</param-name>
    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
  </init-param>

<!--关键部位2,cors.support.credentials项
  1,若需进行用户名密码验证,则必须存在;
  2. 若无效进行用户名密码验证,仅设置跨域,则可删除


  <init-param>
    <param-name>cors.support.credentials</param-name>
    <param-value>true</param-value>
  </init-param>-->
  <init-param>
    <param-name>cors.preflight.maxage</param-name>
    <param-value>10</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

重启tomcat和geoserver

转载自:https://blog.csdn.net/hsg77/article/details/88874241

You may also like...