tomcat编码设置问题(servlet)
//get方式下不需要设置编码(tomcat8以后版本),tomcat8之前需要:
String fname = request.getParameter("fname");
//1.将字符串打散成字节数组
byte[] bytes = fname.getBytes("ISO-8859-1");
//2.将字节数组按照设定的编码重新组装成字符串
fname = new String(bytes,"UTF-8");
//tomcat8之后只需要对post的编码设置,无需对get编码设置
//post方式下,设置编码,防止中文乱码,必须设置在所有获取参数动作之前
request.setCharacterEncoding("UTF-8");