Spring4.0 MVC請(qǐng)求json數(shù)據(jù)報(bào)406錯(cuò)誤的解決方法
Spring4.0 MVC請(qǐng)求json數(shù)據(jù)報(bào)406錯(cuò)誤,如何解決?
解決方法一:
1、導(dǎo)入jackson-core-2.5.1.jar和jackson-databind-2.5.1.jar
2、Spring配置文件添加:
<!-- 避免IE執(zhí)行AJAX時(shí),返回JSON出現(xiàn)下載文件 spring3為:org.springframework.http.converter.json.MappingJacksonHttpMessageConverter spring4為:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <!-- 啟動(dòng)Spring MVC的注解功能,完成請(qǐng)求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /><!-- json轉(zhuǎn)換器 --> </list> </property> </bean>
解決方法二:
1、導(dǎo)入第三方(阿里巴巴)的fastjson包,fastjson-1.2.7.jar
2、Spring配置文件添加:
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- 避免IE執(zhí)行AJAX時(shí),返回JSON出現(xiàn)下載文件 --> <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringCloud中的Hystrix保護(hù)機(jī)制詳解
這篇文章主要介紹了SpringCloud中的Hystrix保護(hù)機(jī)制詳解,Hystrix,英文意思是豪豬,全身是刺,看起來就不好惹,是一種保護(hù)機(jī)制,Hystrix也是Netflix公司的一款組件,需要的朋友可以參考下2023-12-12JavaWeb之Ajax的基本使用與實(shí)戰(zhàn)案例
ajax技術(shù)是使頁(yè)面能局部刷新的一種技術(shù),下面這篇文章主要給大家介紹了關(guān)于JavaWeb之Ajax的基本使用與實(shí)戰(zhàn)案例的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08淺析java中 Spring MVC 攔截器作用及其實(shí)現(xiàn)
本篇文章主要介紹了java中SpringMVC 攔截器的使用及其實(shí)例,需要的朋友可以參考2017-04-04java中如何實(shí)現(xiàn)對(duì)類的對(duì)象進(jìn)行排序
在本篇文章里小編給各位整理一篇關(guān)于java中如何實(shí)現(xiàn)對(duì)類的對(duì)象進(jìn)行排序知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。2020-02-02SpringBoot整合ShardingSphere5.x實(shí)現(xiàn)數(shù)據(jù)加解密功能(最新推薦)
這篇文章主要介紹了SpringBoot整合ShardingSphere5.x實(shí)現(xiàn)數(shù)據(jù)加解密功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06Java Web檢查用戶登錄狀態(tài)(防止用戶訪問到非法頁(yè)面)
一般javaweb網(wǎng)站都有用戶登錄,而有一些操作必須用戶登錄才能進(jìn)行,本文主要介紹了Java Web檢查用戶登錄狀態(tài),具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09java.io.NotSerializableException異常的問題及解決
這篇文章主要介紹了java.io.NotSerializableException異常的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12