在某网站上访问本地Tomcat 8080端口服务,控制台提示“Access to XMLHttpRequest at '
http://localhost:8080/xxx.json' from origin 'http://xxx.com.cn:8090' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.”,这是跨域引起的。
cors error
web.xml文件添加跨域配置
<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>
</filter>
<filter-mappi