加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax结合springmvc报406错误

发布时间:2020-12-16 01:51:52 所属栏目:百科 来源:网络整理
导读:在springmvc中使用ajax发现报了406错误,查了一下: 如下 the resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request “accept” headers 大概意思就是说响应头不一

在springmvc中使用ajax发现报了406错误,查了一下:
如下

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

大概意思就是说响应头不一样,也是springmvc返回的html数据,然后我们网页端接收的是Application/json,所以需要springmvc将返回的数据进行json化处理

而且我的controller是能够获取到值的,更加说明了返回的时候出现问题

所以我们需要引入相关包,让springmvc自动处理即可
如果使用的是maven

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.4.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.1.1</version>
</dependency>

如果上面还不行,请再加一个jackson-annotions的包

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.4.1.1</version>
</dependency>

方法二:
可以手动添加jackson的包即可

其实我觉得只要是个能够解析json的包应该都可以,包括不仅限于这几个。未测试

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读