Springmvc the problem of garbled characters in JSON Chinese strings when Ajax requests are returned

Source: Internet
Author: User

The 1.org.springframework.http.converter.stringhttpmessageconverter class is a class that processes requests or corresponding strings, and the default character set is Iso-8859-1, so garbled when there is Chinese in the return JSON.

2.Stringhttpmessageconverter has a list<mediatype> supportedmediatypes attribute in the parent class to store Stringhttpmessageconverter supports mediatype types that require special handling, if the type of mediatype to be processed is not Supportedmediatypes list, the default character set is used.

3. Workaround, simply add the following code to the configuration file:

<!--SPRINGMVC The JSON value is resolved--><mvc:annotation-driven>    <mvc:message-converters>        < Bean class= "Org.springframework.http.converter.StringHttpMessageConverter" >            <property name= " Supportedmediatypes ">                <list>                    <value>application/json;charset=UTF-8</value>                </list>            </property>        </bean>    </MVC:MESSAGE-CONVERTERS></MVC: Annotation-driven>

4. If you need to handle othermediatype type, you can add other value tags to the list label

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.