码迷,mamicode.com
首页 > Web开发 > 详细

Tomcat的webservice接口访问跨域

时间:2018-08-06 18:25:42      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:app   接口   access   web   name   any   cti   code   map   

tomcat7发布的webservice接口在被用户跨域访问的时候报错

(No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘https://xcx1.winhui.net‘ is therefore not allowed access.)

解决办法

1、下载cors-filter-<version>.jar和java-property-utils-<version>.jar两个jar文件,并将其放在web服务器的classpath路径下,例如tomcat的lib。

cors-filter-2.4.jar java-property-utils-1.9.1.jar 包我这里就不提供了

2、在web.xml中添加CorsFilter过滤器

<filter>
   <filter-name>CorsFilter</filter-name>
   <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

 

3、然后重启tomcat就好了

 备份一下,同时也给更多的水友多一条解决此问题的路径

Tomcat的webservice接口访问跨域

标签:app   接口   access   web   name   any   cti   code   map   

原文地址:https://www.cnblogs.com/Mys-ql/p/9431720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!