SPRINGMVC @responsebody return JSON, Chinese garbled problem resolution.

Source: Internet
Author: User

Springmvc of the @responsebody, return JSON, if there is a solution for garbled Chinese display.

In the SPRINGMVC configuration file

< Bean   class = "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >    </ Bean >

Viewed the source code of Annotationmethodhandleradapter, and found that its default encoding is Stringhttpmessageconverter object with construction parameters.

Continue to drill down, found that the default encoding Stringhttpmessageconverter is "iso-8859-1", no wonder in the Utf-8 display when the display garbled.

Here's the solution:

In Annotationmethodhandleradapter, the encoding format for custom Stringhttpmessageconverter is UTF-8.

<Beanclass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">        < Propertyname= "Messageconverters">            <List>                <Beanclass= "Org.springframework.http.converter.StringHttpMessageConverter">                     < Propertyname= "Supportedmediatypes">                        <List>                            <value>Text/html;charset=utf-8</value>                          </List>                     </ Property>                  </Bean>                 </List>        </ Property>    </Bean>

SPRINGMVC @responsebody return JSON, Chinese garbled problem resolution.

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.