ArcgisServer跨域问题
目录
1:Arcgiserver在火狐和谷歌浏览器下会因为JS同源策略导致请求被拦截,解决办法是在后端直接进行CORS配置,开放出地址给其他客户端。
2:配置方法
- 找到arcgisServer的安装路径下的tomcat容器
<arcgis_server_home>\framework\runtime\tomcat
- 下载必要的两个CORS 包,并添加进tomcat根目录下的lib目录中
cors-filter-1.7.jar ,java-property-utils-1.9.jar
- 修改config目录下的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>
- 重新启动ArcgisServer服务即可。(ArcgisServer服务启动时间比较长,需耐心等候url可以正常访问)