Servlet(六)中文乱码问题
出现中文乱码的原因: 浏览器(请求) 与 服务器(默认编码是iso-8859-1,服务器处理和响应返回) 之间的编码格式不一致 (1)post request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); (2)get String username=new String(request.getParameter("username").getBytes("iso-8859-1"),"utf-8"); response.setContentType("text/html;charset=utf-8"); (3)sendRedirect(); 只是多了个重定向,数据传递 浏览器(请求) -----> 服务器(服务器重定向响应) ------> 浏览器 (重定向请求)------> 服务器 (响应返回) 只需对每次http请求响应都做get或post处理即可 特殊:1、ie6一下版本对奇数数据量可能仍然产生中文乱码 2、实现浏览器下载文件带中文文件名时也可能出现乱码 解决:此时需要使用urlencode对数据变量做url编码 来源: CSDN 作者: 华师混混 链接: https://blog.csdn.net/hunhunpanda/article/details