cnblogs Post date: 2010-08-03 11:46

问题

get方法提交的表单数据中有中文时会出现乱码

原因

get提交的数据在url中,默认不会转换编码(浏览器发送时是utf-8编 码,jsp默认用iso-8859-1编码)

解决

  1. jsp页面首部加入 \<%request.setCharacterEncoding("utf-8");%> 或者使用filter设置编码
  2. 对tomcat配置文件(conf/server.xml)中进行更改:

     <!--    Define a non-SSL HTTP/1.1 Connector on port 8080 -->
        <!-- <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />  -->
        <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" useBodyEncodingForURI="true" disableUploadTimeout="true" />
    
  3. 页面中就可以直接使用request.getParameter("name")