geoserver rest接口跨域访问
我用的2.12.2版本,访问rest接口时遇到了跨域问题,参考http://blog.csdn.net/qq_29176825/article/details/77968307等文章时,发现源码文件中自带了跨域功能,只是默认没有启用。
找到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>
转载自:https://blog.csdn.net/u010791426/article/details/79628329