Tomcat6安装目录/conf/server.conf默认的connector配置如下,
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
默认情况下其URIEncoding =”ISO8859-1”。
为了确保web客户端和服务器编解码正常,在客户端肯定是utf8编码的情况下,处理方式有2种
1) tomcat connector采用默认配置URIEncoding =”ISO8859-1”
client端编码:
URLEncoder.encode(description,"UTF-8");
server端解码:(接收到的为ISO8859-1编码的字符串)
String description = request.getParameter("description");
decDescription = new String(description.getBytes("ISO8859-1"), "UTF-8");
2) 修改tomcat connector配置URIEncoding =”UTF-8”
client端:
URLEncoder.encode(description,"UTF-8");
Server端:
String description = request.getParameter("description");
//此处接收到的description即为UTF-8格式了。