大佬教程收集整理的这篇文章主要介绍了No 'Access-Control-Allow-Origin' header is present on the requested resource,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
今天在使用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.
我先大概描述一下我的应用场景:
我有一批数据,它是存储在MysqL数据库,然后呢,我用jersey写了一些restful接口,供其他应用来查询数据,在这里,我有一个前台网站,这个网站需要调用那个restful接口,以查询相关数据展现在前端,前端是用Angularjs的$http来请求的,但是在请求的时候,出现了以上的跨域问题。
直接找到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>
以上是大佬教程为你收集整理的No 'Access-Control-Allow-Origin' header is present on the requested resource全部内容,希望文章能够帮你解决No 'Access-Control-Allow-Origin' header is present on the requested resource所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。