Spring4.0 MVC請求json數(shù)據(jù)報406錯誤的解決方法
Spring4.0 MVC請求json數(shù)據(jù)報406錯誤,如何解決?
解決方法一:
1、導(dǎo)入jackson-core-2.5.1.jar和jackson-databind-2.5.1.jar
2、Spring配置文件添加:
<!-- 避免IE執(zhí)行AJAX時,返回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> <!-- 啟動Spring MVC的注解功能,完成請求和注解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時,返回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>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
淺析java中 Spring MVC 攔截器作用及其實現(xiàn)
本篇文章主要介紹了java中SpringMVC 攔截器的使用及其實例,需要的朋友可以參考2017-04-04SpringBoot整合ShardingSphere5.x實現(xiàn)數(shù)據(jù)加解密功能(最新推薦)
這篇文章主要介紹了SpringBoot整合ShardingSphere5.x實現(xiàn)數(shù)據(jù)加解密功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06Java Web檢查用戶登錄狀態(tài)(防止用戶訪問到非法頁面)
一般javaweb網(wǎng)站都有用戶登錄,而有一些操作必須用戶登錄才能進行,本文主要介紹了Java Web檢查用戶登錄狀態(tài),具有一定的參考價值,感興趣的可以了解一下2023-09-09java.io.NotSerializableException異常的問題及解決
這篇文章主要介紹了java.io.NotSerializableException異常的問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12