更改Tomcat配置,解决中文乱码问题

1:在TOMCAT自带的例子中(/webapps/examples/WEB-INF/classes/filters)找到2个文件RequestDumperFilter.java,SetCharacterEncodingFilter.java,加入到工程文件中去。

  2:配置 server.xml。

  <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />

  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"  URIEncoding="UTF-8"/>

  加入红色的部门就好了。

 

  3:配置 web.xml  

  <filter>
    <filter-name>Set Character Encoding</filter-name>
      <filter-class>filters.SetCharacterEncodingFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>GBK</param-value>
      </init-param>
    </filter>
    <filter-mapping>
      <filter-name>Set Character Encoding</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

你可能感兴趣的:(tomcat)