jason0401 发表于 2017-2-3 10:24:18

Tomcat get/post提交中文乱码解决办法

首先是get方式提交乱码,修改tomcat的server.xml。在Connector节点添加URIEncoding="UTF-8"

<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--><Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/> 


然后是post方式提交乱码,tomcat中提供了一个filter用于修改request的编码。 文件目录是apache-tomcat-6.0.20\webapps\examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java 在web.xml中配置过滤器指定编码


filter<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />--><filter>  
    <filter-name>SetCharacterEncodingFilter</filter-name>  
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>  
    <init-param>  
        <param-name>encoding</param-name>  
        <param-value>utf-8</param-value>  
    </init-param>  
</filter>  
<filter-mapping>  
    <filter-name>SetCharacterEncodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
</filter-mapping>


  
页: [1]
查看完整版本: Tomcat get/post提交中文乱码解决办法