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);
}
欢迎交流,谢谢大家。
后面发现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);
}
欢迎交流,谢谢大家。
相关文章推荐
- Android socket 使用PrintWriter和BufferedReader发送和接收出现乱码问题解决
- 使用SpringMVC参数传递时,解决get请求时中文乱码的问题
- 解决问题:在使用springmvc的web.xml配置乱码拦截器之后接收的get或者post请求中文还是乱码
- springmvc跳转页面: PrintWriter的使用跳转问题
- SpringMVC中使用jackson,注解@ResponseBody返回中文乱码问题
- 如何彻底解决SpringMVC4.0下使用解决@ResponseBody 中文乱码问题
- [置顶] 使用springmvc接收参数乱码问题
- springMVC4下使用@ResponseBody的中文乱码问题
- SpringMVC使用@ResponseBody输出字符串时遇到的乱码问题及解决办法
- 解决SpringMVC使用@ResponseBody中文乱码(???)问题
- SpringMVC使用@ResponseBody输出字符串时遇到的乱码问题及解决办法
- SpringMVC的ajax的使用及返回中文乱码问题
- SpringMVC使用@ResponseBody输出字符串时遇到的乱码问题及解决办法
- springmvc使用@responsebody返回字符串乱码问题
- 解决springMVC4下使用@ResponseBody的中文乱码问题
- (总结)使用springmvc解决各种乱码问题的大汇总
- 解决springmvc使用@ResponseBody返回String类型字符串中文乱码问题
- springmvc 使用validation校验无法加载properties文件,及验证信息乱码的问题
- 解决springmvc使用ResponseBody注解返回json中文乱码问题
- SpringMVC使用@RequestBody后台返回前台中文字符串乱码的问题解决方案