eclipse编写servlet控制台乱码问题 5
源文件是utf-8编码的,将普通的java文件和servlet文件用eclipse都改成utf-8,然后用bufferreader读取,控制台输出,此时在java中的控制...
源文件是utf-8编码的,将普通的java文件和servlet文件用eclipse都改成utf-8,然后用bufferreader读取,控制台输出,此时在java中的控制台是没有乱码的,但是在servlet中却出现了乱码
展开
1个回答
展开全部
post乱码:可以用过滤器配置在web.xml中
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Get乱码:(1)修改tomcat配置文件添加编码与工程编码一致,如下:
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
(2)另外一种方法在servlet中对参数进行重新编码:
String(request.getParamter("参数").getBytes("ISO8859-1"),"utf-8")
不懂再问我
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Get乱码:(1)修改tomcat配置文件添加编码与工程编码一致,如下:
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
(2)另外一种方法在servlet中对参数进行重新编码:
String(request.getParamter("参数").getBytes("ISO8859-1"),"utf-8")
不懂再问我
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询