http请求后台报406错误

1.springMVC的项目,通过浏览器访问后台方法遇到了报406的错误,找了很多原因,最终发现是因为缺少spring-mvc的json配置。

2.添加依赖:jackson-databind、jackson-core-asl

3.在springMVC.xml中配置

<!-- 解决页面请求报406的错误 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>

4.在此访问即可

原文地址:https://www.cnblogs.com/blue327/p/10090651.html

时间: 2024-07-29 08:10:35

http请求后台报406错误的相关文章

SpringMVC的AJAX请求报406错误

SpringMVC的AJAX请求报406错误原因有两种:1.jackson包没有引入 2.如果已经引入jackson包了还报406的错误,那么就有可能是请求的url路径是.html结尾,但是返回的数据是一个对象,这时浏览器就不知道怎么响应了,因为一般请求.html后缀的页面,返回的一般是个字符串或者页面内容,此时可以在web.xml中再配置一个拦截后缀,如*.action,web.xml可以有多个拦截后缀,请求.action的后缀,浏览器就没有这个限制了

.NET版UEditor报请求后台配置项http错误,上传功能无法使用的错误解决

在配置UEditor的时候,总是报请求后台配置项http错误,上传功能将不能正常使用!,上传图片等功能都无法使用.折磨了一下午,逐步调试发现了错误原因: 根据这行错误我跟踪到了这里: 发现JObject.Parse()的时候抛出了错误,仔细检查下是config.json转换时候不能正常识别,翻了翻配置把这行注释删掉完事:

springMVC浏览器接受json报406错误的解决方法

这个错误还真难搞,头一次遇见还真没有什么好办法解决,上网找了很多资料,一一试过也不能很好的解决,最后经过朋友,同事一起努力,终于征服了.留下笔记,供大家参考: 1.我后台测试代码如下: @RequestMapping("/json") public @ResponseBody String json() { return "this is json"; } @RequestMapping("/json2") public @ResponseBod

浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request &quot;accept&quot; headers

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers 网上关于这个问题有很多说法,有的说spring mvc版本问题的,有说jackson jar包问题问题的,试了下都不可以, 这里的解决方法参考: https://www.cn

Yii2请求,报400错误

出现400错误是yii2.0的csrf防范策略导致 在components里面添加request配置如下: 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => '83r5HbITBiMfmiYPOZFdL-raVp4O1VV4', 'enableCookieValid

记录一次解决httpcline请求https报handshake_failure错误

概述 当使用httpclinet发起https请求时报如下错误: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:1

springmvc报406错误

springmvc出现406,无非就两种情况,第一,百分之九十是json包没加进来,第二,百分之十,就是@ResponseBody返回的的数据,在请求的URL中不能有  .html的后缀

spring mvc 4.1 返回json报406错误的解决办法

浏览器访问,报 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers. 解决办法,检查springmvc的配置文件中有无 <mvc:annotation-driven />

request使用getReader()和getInputStream()获取请求参数报400错误

参考:http://liwx2000.iteye.com/blog/1542431 和http://stackoverflow.com/questions/7318632/java-lang-illegalstateexception-getreader-has-already-been-called-for-this-re 原因:ServletRequest中getReader()和getInputStream()只能调用一次的解决办法 最近使用spring mvc做项目,数据格式是json,