中文乱码

一、Window->Preferences->General ->Content Type->Text->JSP 最下面设置为UTF-8web

二、Window->Preferences->General->Workspace   面板Text file encoding 选择UTF-8spring

三、Window->Preferences->General->Workspace   面板Text file encoding 选择UTF-8tomcat

web.xml中加入:app

<filter>post

<filter-name>CharacterEncodingFilter</filter-name>编码

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>url

<init-param>spa

<param-name>encoding</param-name>xml

<param-value>utf-8</param-value>utf-8

</init-param>

</filter>

<filter-mapping>

<filter-name>CharacterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

以上能够解决post请求乱码问题。

对于get请求中文参数出现乱码解决方法有两个:

修改tomcat配置文件添加编码与工程编码一致,以下:

 

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

另一种方法对参数进行从新编码:

String userName new

String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")

 

ISO8859-1tomcat默认编码,须要将tomcat编码后的内容按utf-8编码

相关文章
相关标签/搜索