The reason that SPRINGMVC's @responsebody returned Chinese characters is that the SPRINGMVC default processing character set is Iso-8859-1, The following code can be seen in the spring Org.springframework.http.converter.StringHttpMessageConverter class:
public static final Charset Default_charset = Charset.forname ("iso-8859-1");
To solve the problem of returning Chinese garbled, there are two, the first is local, only for the return of a method of processing, the second is global, for the entire project, as follows:
The first: Add produces= "Text/html;charset=utf-8 in @requestmapping, such as:
@RequestMapping (value= "/login.do", method=requestmethod.post,produces= "Text/html;charset=utf-8") @ Responsebodypublic String Login (@RequestParam (value= "username") string username, @RequestParam (value= "password") String password) {return Jsonmessageutil.getsuccessjson ("login Successful");}
The second type: Add the following code to the Mvc:annotation-driven in the configuration file:
<mvc:annotation-driven ><!--Message Converter--><mvc:message-converters register-defaults= "true" ><bean class= "Org.springframework.http.converter.StringHttpMessageConverter" ><property name= "supportedmediatypes "Value=" Text/html;charset=utf-8 "/></bean></mvc:message-converters></mvc:annotation-driven ><mvc:resources location= "/resources/" mapping= "/resources/**"/>
For the garbled problem, so that the normal display of Chinese
Solve Springmvc's @responsebody return Chinese garbled