因为我们浏览器请求的数据时utf-8编码,但是tomcat的默认编码确实ISO-8859-1所以我们可以通过
username = new String(username.getBytes("ISO-8859-1"), "utf-8");
这种方式来解决这个问题。
方法二:
就是通过requestt的setCharacterEncoding("utf-8")和response的setCharacterEncoding()方法设置,
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");