解决请求*.html后缀无法返回json数据的问题(SpringMVC项目中tomcat报406错误)

SpringMVC项目中406错误:

在请求返回json数据时
tomcat 报错

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

汉语解释:
由该请求标识的资源仅能够生成具有根据请求“接受”标头不可接受的特征的响应。

原因:在springmvc中请求*.html不可以返回json数据。
由于上述原因造成的,我们可以用一下解决思路,

1. json的jar包没安装。

看文件中有没有json的依赖包,没有的话,pom文件加入jar包

<!-- Jackson Json处理工具包 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>${jackson.version}</version>
			</dependency>

2. 请求URL是以.html结尾。(修改web.xml,添加url拦截格式。)

在js生成请求的地方更改为以.action结尾
在这里插入图片描述
web.xml再加上接受.action请求
在这里插入图片描述

发布了15 篇原创文章 · 获赞 0 · 访问量 496

猜你喜欢

转载自blog.csdn.net/qq_36335126/article/details/103941088