Tomcat 默认是用 ISO-8859-1 处理URI中的参数
所以,如果URI参数中含UTF-8编码的话,如果直接读取会出现乱码。
两个解决办法 :
1. 改配置,在tomcat的server.xml 的connector中加入URIEncoding="UTF-8"
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" compression="on" compressionMinSize="50" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" URIEncoding="UTF-8" />
2. 或者改程序,对接受到的参数进行转换
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //.... String value=req.getParameter(key).getBytes("ISO-8859-1"),"UTF-8") //... }