Spring 3.0 @ResponseBody Comments Return Chinese question mark garbled solution

Source: Internet
Author: User

A few days ago to the company to do projects, a long time without contact with the Java project I, encountered a problem, is that I am using the asynchronous to the controller query, and then return the Jaon string to the foreground, the string contains Chinese, so I directly use the @responsebody annotation, to return to the foreground.

But Chinese has always been a question mark back to the foreground. After several attempts, in the configuration file to add the character set or useless, I found that I did not write wrong, and then a sudden thought is because misplaced location, sure enough, the character set should be placed in the package scan configuration before the scan is complete before you set the character is meaningless. So the following configuration is the correct workaround:

     <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>      <!--Configuring the Package scanner -    <Context:component-scanBase-package= "com. Canteenevalute.controller "></Context:component-scan>    <!--Configure view Resolution -    <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">        < Propertyname= "prefix"value= "/web-inf/"></ Property>        < Propertyname= "suffix"value= ". jsp"></ Property>    </Bean>    </Beans>

Spring 3.0 @ResponseBody Comments Return Chinese question mark garbled solution

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.