servlet中doPost()方法中設置request、response的編碼(解決中文亂碼),能夠以下設置:編碼
response.setCharacterEncoding("utf-8");server
request.setCharacterEncoding("utf-8");xml
可是在doGet()方法中設置request的編碼仍是不能解決中文亂碼。utf-8
可使用以下方法:servlet
把Tomcat下面conf文件夾下的server.xml文件中:io
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" />亂碼
修改成:coding
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />request
便可方法