您的位置:首页 > 编程语言 > Java开发

SpringMvc使用PrintWriter乱码的问题

2016-08-10 12:05 776 查看
最开始我以为在web.xml中配置了SetCharacterEncoding即可,但是后面使用PrintWriter写数据到界面却出现乱码的情况。

后面发现xml中配置是设置了编码集,却没有设置contextType,所以才会出现这样的情况。

解决方法如下:

@RequestMapping(value="/getPerson")
public void getPerson(Person p,PrintWriter out,HttpServletResponse response) throws IOException{
response.setContentType("text/html;charset=utf-8");
out=response.getWriter();
out.write("hello,"+p);
}

欢迎交流,谢谢大家。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  乱码 spring mvc