在 Servlet doGet 方法最上面加上
request.setCharacterEncoding("utf-8");
不要在其他方法里面加,可能没用
如果上面的方法不起作用,就用下面方法,基本能解决所有的字符串编码问题
public class ChineseEncoding {
public static String changeStr(String input) {
try {
input = new String(input.getBytes("iso-8859-1"), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return input;
}
}