标签:iso tomcat tomcat8 方法 mapping server nec 默认 tchar
tomcat8自动处理了get 请求的乱码,默认为UTF-8,
而tomcat7默认为iso-8859-1
解决方法很简单: 修改tomcat下的conf/server.xml文件,找到如下代码:
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" /> 这段代码规定了Tomcat监听HTTP请求的端口号等信息。可以在这里添加一个属性:URIEncoding,
即可让Tomcat(默认编码)以ISO-8859-1的编码处理get请求。更改后的代码如下所示: URIEncoding="ISO-8859-1"
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="ISO-8859-1"/>
我们只要处理post 乱码问题
(1): request.setCharacterEncoding("UTF-8");
(2):过滤器处理
<!--post 请求乱码--> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
标签:iso tomcat tomcat8 方法 mapping server nec 默认 tchar
原文地址:https://www.cnblogs.com/jsbk/p/9652651.html