解决tomcat中文乱码问题

(1)Tomcat 的 conf 下的server.xml文件中将

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
里添加上后面3个编码的设置

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"

redirectPort="8443"

useBodyEncodingForURI="true"

IEncoding="utf-8"

URIEncoding="utf-8"/>

(2)

然后在servlet中配置如下:
如果你用的是 post方式
解决方案:
request.setCharacterEncoding("utf-8");

response.setCharacterEncoding( "utf-8" );

get方式

String string = request。getParamers("");

String = new String(string.getBytes("ISO8859-1","utf-8"));

(3)jsp页面中 pageEncoding="UTF-8"

(4)如果你用的是Eclipse或者MyEclipse的话,那么你在window 下的preferences中的左上角的输入框中输入spelling 在spelling这个页面中看看Encoding 默认是否设置为utf-8

然而,我是因为

req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html:charset=utf-8");

没有放在最前面出错的哈哈哈

(这篇只用于错误记录,不做原理说明)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值