SpringMVC异常报406 (Not Acceptable)的解决办法
2017-10-17 15:04
549 查看
使用了SpringMVC,同时在web.xml中的*.html这样配置。其中对应的Controller方法如下:
当访问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
@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
相关文章推荐
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- gMVC异常报406 (Not Acceptable)的解决办法
- SpringMvc406(Not Acceptable)的解决办法
- SpringMVC ajax 请求报错:406 Not Acceptable 的解决办法 使用@ResponseBody注解
- Spring Boot 406(type=Not Acceptable, status=406)异常解决办法
- SpringMVC异常报406的解决办法
- 解决 ajax报错406,springMVC报错406,页面报错406解决办法
- SpringMVC使用@ResponseBody时报406错误解决办法
- SpringMVC出现406错误的解决办法
- 关于springMVC 接收date 类型为空时候的异常解决办法
- SpringMVC 利用@ResponseBody注解返回Json时,出现406 not acceptable 错误的解决方法。
- springmvc 页面400异常,访问不到controller原因及解决办法
- SpringMVC异常报406 (Not Acceptable)的解决办法
- Spring MVC json问题(406 Not Acceptable) 解决办法