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请求