@Responsebody utf8 Chinese gibberish
来源:互联网 发布:linux shell sleep 编辑:程序博客网 时间:2024/06/05 13:28
Chinese gibberish–>controller return a String “中文” to html, but html shows “??”.
create a class like
package com.fc.test.utils;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.BeanPostProcessor;import org.springframework.http.MediaType;import org.springframework.http.converter.StringHttpMessageConverter;import java.nio.charset.Charset;import java.util.ArrayList;import java.util.List;/** * Created by */public class UTF8StringBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object o, String s) throws BeansException { if (o instanceof StringHttpMessageConverter){ MediaType mediaType = new MediaType("text", "plain", Charset.forName("UTF-8")); List<MediaType> types = new ArrayList<MediaType>(); types.add(mediaType); ((StringHttpMessageConverter) o).setSupportedMediaTypes(types); } return o; } @Override public Object postProcessAfterInitialization(Object o, String s) throws BeansException { return o; }}
and add it a bean in spring-mvc.xml
<bean class="com.fc.test.utils.UTF8StringBeanPostProcessor"/>
阅读全文
0 0
- @Responsebody utf8 Chinese gibberish
- **"Chinese"
- chinese
- responseBody
- @ResponseBody
- @ResponseBody
- @responsebody
- @ResponseBody
- @ResponseBody
- @ResponseBody
- @ResponseBody
- @responsebody
- @ResponseBody
- @ResponseBody
- @ResponseBody
- @ResponseBody
- @responsebody
- @ResponseBody
- 【HeartMa Java学习总结】Java基础
- vim编辑器
- Listview嵌套Listview外部item点击事件无效的解决办法
- 从Hadoop框架与MapReduce模式中谈海量数据处理
- 用代理软件之后有的页面显示不出来
- @Responsebody utf8 Chinese gibberish
- 精益设计,敏捷开发,一个都不能少
- 将Json数据转换为ADO.NET DataSet对象
- TF/02_TensorFlow_Way/01 02
- java学习各位大牛的网址
- PHP 生成WSDL 以及 提供SOAP服务
- String类中方法的使用举例
- 程序实现postgresql备份还原
- [leetcode]Longest Common Prefix