No 'Access-Control-Allow-Origin' header is p
发布时间:2020-12-17 09:59:51 所属栏目:安全 来源:网络整理
导读:今天在使用Angularjs ajax调用restful接口的时候,遇到了一个跨域问题: XMLHttpRequest cannot load http://localhost: 8080 /***/ v1/rest /***/ ***. No 'Access -Control-Allow-Origin' header is present on the requested resource. Origin 'http ://l
今天在使用Angularjs ajax调用restful接口的时候,遇到了一个跨域问题: XMLHttpRequest cannot load http://localhost:8080/***/v1/rest/***/***. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:34370' is therefore not allowed access.
我先大概描述一下我的应用场景: 解决方案(参考网站): 直接找到Tomcat安装目录下的conf/web.xml,然后加入以下代码: <filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:Apache Tomcat 是从7.0.41版本开始支持CORS,如果是这之前的版本,请查找其他相关文献。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容