JSP传值到servlet到数据库乱码问题

在 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;
	}

}

猜你喜欢

转载自blog.csdn.net/qq_42651904/article/details/82889111