ajax请求json字符串springMVC返回中文乱码解决办法
2018-09-27 19:47
274 查看
方法一:
在@RequestMapping(value="/ValidMobile",produces = "text/html;charset=UTF-8")中,加上produces = "text/html;charset=UTF-8"。
[code] @RequestMapping(value="/ValidMobile",produces = "text/html;charset=UTF-8") @ResponseBody public String validMobile(@RequestBody String param) { User user = new Gson().fromJson(param, User.class); ResponseBean rb = new ResponseBean; rb.setResultMsg("中文乱码"); return new Gson().toJson(rb); }
方法二(推荐):
在spring-servlet.xml配置文件中加入
[code]<!-- 注解驱动 --> <mvc:annotation-driven> <!-- 指定http返回编码格式 --> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>*/*;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>阅读更多
相关文章推荐
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- SpringMVC Ajax请求时返回json中文字符串的乱码问题的解决方案
- SpringMVC Ajax返回的请求json 的方式来解决在中国字符串乱码问题
- 使用ajax请求SpringMVC返回Json出现乱码解决方法
- DJANGO中,用QJUERY的AJAX的json返回中文乱码的解决办法
- SpringMVC 学习-返回字符串中文乱码问题解决
- springMVC4.2返回日期格式化的json串,同时解决中文乱码
- springmvc 发送ajax中文乱码的几种解决办法
- ztree通过ajax加载json数据中文乱码的解决方法:springmvc配置
- SpringMVC返回JSON乱码问题解决办法
- springmvc 发送ajax中文乱码的几种解决办法
- 解决springmvc使用@ResponseBody返回String类型字符串中文乱码问题
- 用ajax传递json到前台中文出现问号乱码问题的解决办法
- springMVC返回json数据时,字符串中文乱码
- Ajax 上传文件返回JSON字符串FireFox解析出来后带有<pre>标签解决办法
- ajax请求数据,Json返回到页面的数据出现中文乱码问题。
- SpringMVC被ajax调用返回字符串时乱码解决方法
- 解决springmvc使用ResponseBody注解返回json中文乱码问题
- 使用ajax请求 返回Json出现乱码解决方法
- 返回json字符串,并解决中文乱码问题