博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java后台接口SSM框架解决跨域问题
阅读量:6913 次
发布时间:2019-06-27

本文共 1572 字,大约阅读时间需要 5 分钟。

这几天和前端对接接口,前端的错误信息是:

 

 注释:
  Failed to load http://192.168.3.3:8080/Light_Push/webFrames.action?page=1&searchProject=1&page=1&searchProject=1: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin              'http://localhost:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

前端用了vue,axios(http客户端)
后端ssm框架,spring版本是3.2.13

发现可以从后台spring跨域着手解决

解决跨域方法:

第一步:导入jar包

  cors-filter-1.7.jar、java-property-utils-1.9.jar

  下载地址:http://pan.baidu.com/s/1pLkLPGJ

第二步:在web.xml文件配置

<filter>

  <filter-name>CORS</filter-name>
  <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
  <init-param>
   <param-name>cors.allowOrigin</param-name>   <!--配置授信的白名单的域名! -->
   <param-value>*</param-value>
  </init-param>
  <init-param>
   <param-name>cors.supportedMethods</param-name>
   <param-value> GET, POST, HEAD, PUT, DELETE </param-value>
  </init-param>
  <init-param>
   <param-name>cors.supportedHeaders</param-name>
   <param-value> Accept, Origin, X-Requested-With, Content-Type, Last-Modified </param-value>
  </init-param>
  <init-param>
   <param-name>cors.exposedHeaders</param-name>
   <param-value>Set-Cookie</param-value>
  </init-param>
  <init-param>
   <param-name>cors.supportsCredentials</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>CORS</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

转载于:https://www.cnblogs.com/Sailsail/p/7683939.html

你可能感兴趣的文章
使用Cobbler2.4.0批量自动安装Esxi5.5
查看>>
我的友情链接
查看>>
Nagios 系统监控
查看>>
Python-w3
查看>>
解决Python开发过程中依赖库打包问题的方法
查看>>
Java封装C++类的几个关键技术点
查看>>
架构设计:系统间通信(35)——被神化的ESB(下)
查看>>
unix 高级IO 文件锁
查看>>
我的友情链接
查看>>
Linux find 用法
查看>>
大型分布式网站架构技术总结
查看>>
十种排序算法的C++泛型实现
查看>>
momgodb 备份与恢复
查看>>
阿里腾讯云物理服务器镜像制作工具
查看>>
linux系统定时重启
查看>>
C++之格式化输出
查看>>
sublime text2 快速生成HTML头部信息Emmet(zen coding)
查看>>
symantec backup exec 备份exchange VSS错误
查看>>
ttlsa教程系列之MySQL---MySQL/Galera集群-多主高可用性负载均衡
查看>>
利用好快捷方式/组合键/鼠标动作,使用桌面工作效率更高
查看>>