SpringMVC异常报406 (Not Acceptable)的解决办法
使用了SpringMVC,同时在web.xml中的*.html这样配置。其中对应的Controller方法如下:
@RequestMapping(value = "/keyword")
@ResponseBody
public List<String> searchKeyword(String keyword) {
return new Person();
}
当访问http://localhost:8085/keyword.html?keyword=关键字,报406错如下:
Failed to load resource: the server responded with a status of 406 (Not Acceptable) : The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request “accept” headers ()
- 报406的错误,很多博客都说没有对应的JSON依赖,加上去就好了。但是我都配置好了的,而且同一项目其他模块是可以的,这样可以排除。
- 既然不是依赖的问题,那又是什么原因呢?后来想可能是上面的url-pattern配置.html的缘故,同时发现返回的Content-Type是text/html而不是json,于是我改成其他的比如.json就没问题了。但是如果我还是想使用*.html就没法返回JSON对象了,不知道这算不算SpringMVC的bug。
另外附上一个更详细的解释:http://blog.csdn.net/hedandan160/article/details/38294357
还没有评论,来说两句吧...