在开发中,前端同事调用后端同事写好的接口,在地址中是有效的,但在项目的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 问题的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 跨域问题解决----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 ...

  5. 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 ...

  6. .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 ...

  7. 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 ...

  8. (转)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 ...

  9. 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 ...

随机推荐

  1. LC 384. Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  2. linuxs上mono

    当前,在Linux系统上架设ASP.NET网站.建设WEB应用工程项目已经在国内流行起来,而“Mono+Jexus”架构模式是Linux承载ASP.NET企业级应用的极为重要的架构方式,这种架构中,J ...

  3. JVM内存模型及配置参数

    JVM 分为堆.栈.方法区.程序计数器.本地方法栈 栈内存存放局部变量表.操作栈.动态链接.方法出口等信息 1.  局部变量表存放了编译期可知的各种基本数据类型(boolean.byte.char.s ...

  4. redis(3)主从与集群

    一.主从架构 yum安装的redis cd /etc/ cp redis.conf /etc/slave.conf vim slave.conf bind 192.168.42.7 slaveof p ...

  5. jdk 1.8中的list排序

    首先看看collections实现 public static <T> void sort(List<T> list, Comparator<? super T> ...

  6. Eclipse MAT和jvisualvm分析内存溢出

    ---------------------------------------------mac os版------------------------------------------------ ...

  7. 14 count(*)

    14 count(*) count(*)实现方式 首先要声明,在不同的mysql引擎中,count(*)有不同的实现方式. --myisam引擎把一个表的总行数存在了磁盘,因此执行count(*)的时 ...

  8. C++学习笔记-模板

    模板把函数或类要处理的数据类型参数化,表现为参数的多态性,称为类属.模板用于表达逻辑结构相同,但具体数据元素类型不同的数据对象的通用行为. 什么是模板 类属--类型参数化,又称参数模板 使得程序(算法 ...

  9. C学习笔记-结构体与二进制文件增删改查

    使用结构体整理数据,然后利用二进制存储文件,这样存储的文件类似于数据库,可以实现文件的增删改查 定义结构体 struct student { unsigned int ID; char name[20 ...

  10. alembic常用命令和经典错误解决办法