1)解决post的中文乱码问题
byte[] bytes=username.getBytes("ISO-8859-1");
username=new String(bytes,"utf-8");
简化版:
request.setCharacterEncoding("utf-8");
2)解决get的中文乱码问题
1)byte[] bytes=username.getBytes("ISO-8859-1");
username=new String(bytes,"utf-8");
2)username = URLEncoder.encode(username, "ISO-8859-1"); //编码
username = URLDecoder.decode(username, "utf-8");//解码
3) 修改tomcat默认解码集
配置tomcat/server.xml 在<Connector> 添加 URIEncoding="utf-8"