Spring 4.0 MVC request json datagram 406 error, how to solve it?
Solution 1:
1. Import jackson-core-2.5.1.jar and jackson-databind-2.5.1.jar
2. Add Spring configuration file:
<!-- Avoid the return of JSON when IE executes AJAX, download file spring3 is: org.springframework.http.converter.json.MappingJacksonHttpMessageConverterspring4 is: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter --> <bean id="mappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <!-- Start Spring MVC's annotation function, completes the mapping of requests and annotations POJOs --> <bean> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /><!-- json converter--> </list> </property> </bean>
Solution 2:
1. Import the fastjson package of third-party (Alibaba), fastjson-1.2.7.jar
2. Add Spring configuration file:
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- Avoid download files when IE executes AJAX --> <bean id="fastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.