问题描述

通过ajax访问Web服务器(Tomcat7.0.42)中的json web service接口的时候,报以下跨域问题:

XMLHttpRequest cannot load http://localhost:8080/get-employees-by-name/name/admin. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' 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>
<filter>

3、重启Web服务器即可。

参考资料

1、http://stackoverflow.com/questions/17267023/tomcat-7-cors-filter

2、http://software.dzhuvinov.com/cors-filter-installation.html

最新文章

  1. 自己用js实现全屏滚动
  2. Manacher&#39;s Algorithm 马拉车算法
  3. iOS 线程间共享资源添加排它锁
  4. Webpack打包工具实时更新操作(启用观察者模式)
  5. innerHtml innerText textContent兼容性问题
  6. iOS SQLite 增删改查的封装(关系型)
  7. demo16Toast
  8. 状态压缩dp 入门
  9. unity3d中切换武器
  10. js跟随鼠标移动的写法
  11. Maven快速搭建GUI项目
  12. HTML5入门必知
  13. 【JVM虚拟机】(2)---GC 算法与种类
  14. mysql 使用正则表达式查询
  15. [转] offsetParent 到底是哪一个?
  16. laravel command
  17. C#控件方法及属性大全,望补充
  18. Java学习个人备忘录之内部类
  19. 启动hbase输出ignoring option PermSize=128m; support was removed in 8.0告警信息
  20. Word2Vec词向量(一)

热门文章

  1. poj 2378 (dijkstra)
  2. VIM基础
  3. ios 汉字字符串数组拼音排序
  4. /etc/securetty文件
  5. 事件查看器事件ID部分说明
  6. Win8环境WPF打开和关闭软键盘
  7. Effective C++ -----条款22:将成员变量声明为private
  8. HDU 4949 Light(插头dp、位运算)
  9. zsh 通信脚本
  10. 【processing】小代码3