JavaWeb解决中文乱码
1、Get请求,方案有两种
A:修改Tomcat配置文件 server.xml URIEncoding="UTF-8"
如:<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8445" URIEncoding="UTF-8" />
B:将从Request作用域中取的参数按iso-8859-1编码得byte值,再转成utf-8编码字符串
如: String userName= request.getParameter("userName");
userName = new String(userName.getBytes("iso-8859-1"),"utf-8");
2、POST请求
request.setCharacterEncoding("utf-8");