其实flex已经基本上退出了历史舞台。
但是由于公司还有一些老项目需要维护。
因此。特记录一下。flex开发中。地图服务跨域配置问题。
加载geoserver wms服务。除了服务本身需要配置跨域之外。
1、配置geoserver本身的跨域配置。
找到geoserver-2.12.2\src\web\app\src\main\webapp\WEB-INF\web.xml中
<!-- Uncomment following filter to enable CORS -->
<!-- <filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter> -->
<!-- Uncomment following filter to enable CORS -->
<!-- <filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> -->
放开注释,修改为
<!-- Uncomment following filter to enable CORS -->
<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,PUT</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>x-requested-with,content-type</param-value>
</init-param>
</filter>
<!-- Uncomment following filter to enable CORS -->
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、配置flex需要的跨域策略文件。crossdomain.xml文件。
既然是 Flex 跨域访问问题,那么就添加跨域文件吧。关键是 geoserver 网站的根目录的文件路径到底在哪呢,跨域文件到底放在什么地方。怎样才能使下面的地址能够访问到:
[plain] view plaincopy
http://[GeoServerIP]:[PORT]/corssdomain.xml
http://[GeoServerIP]:[PORT]/corssdomain.xml
在老外的网站上发现了解决办法:在Geoserver安装目录下找到 webapps 文件夹,在下面创建 root 文件夹,把跨域文件放在里面,重启Geoserver 就乐吧。
[plain] view plaincopy
C:\Program Files\GeoServer 2.2.2\webapps\root\crossdomain.xml
C:\Program Files\GeoServer 2.2.2\webapps\root\crossdomain.xml
文件内容如下:
[html] view plaincopy
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
标签: arcgis