jsckson,想說愛你不容易啊。。。406錯誤

來源:互聯網
上載者:User

標籤:weight   add   top   net   source   spring配置   url   ges   display   

最近使用spring4.0的Mvc,json請求時,用戶端報錯,406 Not Acceptable

解決方案一:

1、匯入第三方的jackson包,jackson-mapper-asl-1.9.7.jar和jackson-core-asl-1.9.7.jar。

2、spring設定檔添加:

 

[html] view plain copy 
  1. <mvc:annotation-driven/>  
  2.   
  3. !-- 避免IE執行AJAX時,返回JSON出現下載檔案 -->    
  4. <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    
  5.     <property name="supportedMediaTypes">    
  6.         <list>    
  7.             <value>text/html;charset=UTF-8</value>    
  8.         </list>    
  9.     </property>    
  10. </bean>    
  11.   
  12. <!-- 啟動Spring MVC的註解功能,完成請求和註解POJO的映射 -->    
  13. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">    
  14.     <property name="messageConverters">    
  15.         <list>    
  16.             <ref bean="mappingJacksonHttpMessageConverter" /><!-- json轉換器 -->    
  17.         </list>    
  18.     </property>    
  19. </bean>   


解決方案二:

 

 

1、匯入第三方的fastjson包,fastjson-1.1.34.jar

2、Spring設定檔添加:

[html] view plain copy 
  1. <mvc:annotation-driven>  
  2.     <mvc:message-converters register-defaults="true">  
  3.         <!-- 避免IE執行AJAX時,返回JSON出現下載檔案 -->  
  4.         <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
  5.             <property name="supportedMediaTypes">  
  6.                 <list>  
  7.                     <value>application/json;charset=UTF-8</value>  
  8.                 </list>  
  9.             </property>  
  10.         </bean>  
  11.     </mvc:message-converters>  
  12. </mvc:annotation-driven>  

jsckson,想說愛你不容易啊。。。406錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.