SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题
在开发中,前端同事调用后端同事写好的接口,在地址中是有效的,但在项目的ajax中,浏览器会报 "No 'Access-Control-Allow-Origin' header is present on the requested resource"的错误。
这是由于浏览器禁止ajax请求本地以外的资源,解决办法如下:
后端同事在Controller层的类上增加@CrossOrign注解,当前文件的所有接口就都可以被调用。
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @CrossOrigin
@RestController
@RequestMapping("test")
public class TestController { @RequestMapping("/one")
public Object one(HttpServletRequest request){
System.out.println("请求成功");
return "请求成功";
} .... }
SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题的更多相关文章
- WCF REST开启Cors 解决 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 405.
现象: 编写了REST接口: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(UriTemp ...
- Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.
Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is presen ...
- java、ajax 跨域请求解决方案('Access-Control-Allow-Origin' header is present on the requested resource. Origin '请求源' is therefore not allowed access.)
1.情景展示 ajax调取java服务器请求报错 报错信息如下: 'Access-Control-Allow-Origin' header is present on the requested ...
- 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'
NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...
- has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
前端显示: has been blocked by CORS policy: Response to preflight request doesn't pass access control che ...
- .Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
网页请求报错: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Or ...
- js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource
js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...
- (转)AJax跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource
在本地用ajax跨域访问请求时报错: No 'Access-Control-Allow-Origin' header is present on the requested resource. Ori ...
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
今天做一个AJAX案例时,浏览器监控到如下错误: XMLHttpRequest cannot load http://54.169.69.60:8081/process_message. No 'Ac ...
随机推荐
- centos 6和centos7关闭防火墙的方法
centos 6 关闭命令: service iptables stop 永久关闭防火墙:chkconfig iptables off 两个命令同时运行,运行完成后查看防火墙关闭状态 ...
- DP&图论 DAY 5 上午
DP&图论 DAY 5 上午 POJ 1125 Stockbroker Grapevine 有 N 个股票经济人可以互相传递消息,他们之间存在一些单向的通信路径.现在有一个消息要由某个人开 ...
- leetcode73矩阵置零
https://leetcode-cn.com/problems/set-matrix-zeroes/ 解答: 两种方法时间复杂度都为O(mn) O(m+n)空间方法: 用两个容器储存为0的行和列 c ...
- C实现通讯录管理系统(亮点:纯链表实现、子串匹配,文件读写)
题目:通讯录管理程序 问题描述 编写一个简单的通讯录管理程序.通讯录记录有姓名,地址(省.市(县).街道),电话号码,邮政编码等四项. 基本要求 程序应提供的基本基本管理功能有: 1) 添加:即增加一 ...
- git介绍以及常用命令操作
一.git与SVN的对比[面试] ①git是分布式的,SVN是集中式的(最核心) ②git是每个历史版本都存储完整的文件,便于恢复,SVN是存储差异文件,历史版本不可恢复(核心) ③git可离线完成大 ...
- message-digest algorithm 5
using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptograph ...
- git 提交项目到远程仓库,简单实现忽略 node_modules文件
在项目根目录中创建 .gitignore文件 在文件中添加你要忽略的文件 .DS_Store node_modules /dist # local env files .env.local .env. ...
- VS 特殊注释
任务注释(添加此注释后,点击视图->任务列表,可以看到TODO注释的位置)://TODO: (未实现)……//UNDONE:(没有做完)……//HACK:(修改)……
- 机器学习笔记:支持向量机(svm)
支持向量机(svm)英文为Support Vector Machines 第一次接触支持向量机是2017年在一个在线解密游戏"哈密顿行动"中的一个关卡的二分类问题,用到了台湾教授写 ...
- C学习笔记-结构体
结构体的定义和初始化 结构体是简单数据类型的综合 struct man { char name[100]; int age; }; struct man m = { "tom", ...