- request.setCharacterEncoding("utf-8");
- response.setContentType("text/html;charset=utf-8");
你确定页面的pageEncoding是utf-8的话,那就再看看tomcat的设置<Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"redirectPort="8443" />
注意一定要和url中的编码一直,我的<a href=>链接的是utf-8格式的,而tom猫中uriencoding是gb2312的所以会出现乱码
还有一点,form表单提交的不要也误认为为utf-8了哦,
<form action="zhiri_manage" method="post" >
值日1:<input type="text" name="name1">值日2:<input type="text" name="name2" >
<input type="submit" value="安排">
zhiri.setName1(new String(name1.getBytes("ISO8859-1"),"utf-8"));
zhiri.setName2(new String(name2.getBytes("ISO8859-1"),"utf-8"));
mysql数据库中的编码为gbk,因此又要转
zhiri.setName1(new String(name1.getBytes("utf-8"),"gbk"));
zhiri.setName2(new String(name2.getBytes("utf-8"),"gbk"));
new zhiriManage().insert(name1, name2);