The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

网上关于这个问题有很多说法,有的说spring mvc版本问题的,有说jackson jar包问题问题的,试了下都不可以,

这里的解决方法参考:

https://www.cnblogs.com/1315925303zxz/p/7404299.html

https://blog.csdn.net/lkwan123/article/details/73385025

我这里报错的原因是因为复制粘贴了一个 produces = "text/html;charset=UTF-8"

这个是解决http请求响应的乱码问题,在@RequestMapping注解上使用produces属性来快速解决,实际上工程配置里面已经加了配置解决乱码问题。请求的后缀.html,会欺骗浏览器当做一个静态网页来解析,是一个简单的SEO优化。一般来说是没问题的。但是这里我们使用了@ResponseBody,返回数据后缀是,.json,但是我们的映射器后缀又是.html.最后浏览器收到数据不知该以哪种类型数据来进行解析,所以就会报406状态码。

解决这种问题的方式有俩种:

一是直接将produces属性去掉,万一出现了乱码则在配置文件或编解码的方式处理,

二是先将对象转成json数据,然后可以使用produces属性解决乱码问题。

浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers的更多相关文章

  1. 解决The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

    SpringMVC中当在浏览器中输入对应的MappingUrl时,报The resource identified by this request is only capable of generat ...

  2. 【406错误】 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

    今天遇到一个奇怪的错误,关于Springmvc的,我明明在Controller方法中写了@ResponseBody,返回一个Map,结果报了406错误. 结果发现,少了一个jar包: 加上去就没事了.

  3. The resource identified by this request is only capable of generating responses with characteristics

    [转]今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only cap ...

  4. SpringMVC_The resource identified by this request is only capable of generating responses with characteristics

    今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only capabl ...

  5. SpringMVC的AJAX请求报406错误

    SpringMVC的AJAX请求报406错误原因有两种:1.jackson包没有引入 2.如果已经引入jackson包了还报406的错误,那么就有可能是请求的url路径是.html结尾,但是返回的数据 ...

  6. 使用AJAX报406错误

    使用AJAX报406错误,基本有一下两种情况: (1)90%的可能是没有添加jackson包: (2)10%的可能是请求的url后缀是*.html 在springmvc里面,如果请求的是*.html, ...

  7. springMVC下ajax获取后台参数直接走错误或者报406错误问题解决

    直接走错误: 返回的结果是否json化,直接返回非字符串的结果会走ajax的error函数. 报406错误: 我在学习springmvc过程中(我的项目是配置的后缀是.html),从controlle ...

  8. springmvc项目,浏览器报404错误的问题

    问题描述: 建立了web工程,配置pom.xml,web.xml,编写controller类,在spring-mvc-servlet.xml文件中指定开启注解和扫描的包位置<mvc:annota ...

  9. http请求后台报406错误

    1.springMVC的项目,通过浏览器访问后台方法遇到了报406的错误,找了很多原因,最终发现是因为缺少spring-mvc的json配置. 2.添加依赖:jackson-databind.jack ...

随机推荐

  1. ThreadLocal 应用

    利用threadLocal 把拦截器中的对象传递到controller或service中 1.可以用 request 携带数据. 2.更优雅的方式是用threadlocal. 请求进入tomcat 和 ...

  2. javascript笔记收集

    因为前端编程的兴起, 慢慢地对css/javascript越来越淡, 偶尔用一下,得查半天资料. 这里就收藏一下比较生僻, 但是做工具时会用到的. json获取属性名 Object.keys(), 只 ...

  3. LeetCode--049--字母异位词分组(java)

    给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串. 示例: 输入: ["eat", "tea", "tan&quo ...

  4. drf 搜索功能

    from django_filters.rest_framework import DjangoFilterBackend from rest_framework import viewsets fr ...

  5. python 生成多维数组

    在刷题时用到了数组,因为不提供三方库所以不能使用Numpy.想如何通过python列表模拟数组. 第一种方法 """ 生成n*m的初始值为0的矩阵 "" ...

  6. Delphi 清理程序内存

    procedure ClearMemory;begin        if Win32Platform = VER_PLATFORM_WIN32_NT then        begin        ...

  7. 攻防世界 | level2

    # ! /usr/bin/env python # -*- coding:utf-8 -*- from pwn import * context.log_level = 'debug' elf = E ...

  8. linux之yum源的RPM软件包管理

    1.yum源的配置文件 路径:vim /etc/yum.repos.d/CnetOS-Base.repo 文件格式: 2.yum查询 yum list 查询所有可用软件包 yum search 包名 ...

  9. js初步简单的编程代码

    简单图片切换编码demo图片地址自行替换 简单图片切换编码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  10. LintCode之两两交换链表中的节点

    题目描述: 我的思路: 由题目描述可知,题目是要求将第一个与第二个节点,第三个与第四节点....进行交换,而进行交换时只用将节点的值进行交换即可.需要注意的是:当链表为null或者当链表只有一个节点时 ...