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