服务气端解决乱码:
如果是post的方式提交的话,直接设置request.setCharacterEncoding("utf-8");
如果是get方式提交的话
1、手动转码,比如接收到了用户名username,要先解码,再编码
username = URLEncoder.encode(username,"Iso-8859-1");
username = URLDecode.decode(username,"utf-8");
或者username = new String(username.getBytes("Iso-8859-1"),"utf-8");
2、修改tomcat/server.xml
在<connector>添加URLEncoding = "utf-8"
浏览器端解决乱码(浏览器端默认用GBK的方式解析,所以服务器里面要设置一下,告诉浏览器用哪种方式解析)
response.setCharacterEncoding("utf-8")
response.setContentType("text/xml");
或者
response.setContentType("text/xml;charset=utf-8");