ibatis 保存修改时都是乱码? 这个问题困恼了我好几天,我很清楚要保证不是乱码,要从html页面一直到数据库, 都为一种编码,我用的是UTF-8,从页面到java程序,再到数据库,所有的设置都查过了 但是还是乱码!我用的技术框架是spring + ibatis + mysql,在我本地运行都很正常,但放到租用的虚拟空间保存修改时就出现乱码。数据库连接的配置文件:jdbcUrl=jdbc:mysql://127.0.0.1:3306/newdb?useUnicode=TRUE&characterEncoding=utf8
user=root
password=123456
minPoolSize=5
maxPoolSize=50注册页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>注册页面</title>
<meta http-equiv="keywords" content="" />
<meta http-equiv="description" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="verify-v1" content="Bc3Pi9T36s2ZJxgj0Kycbd1JFj93kMytn2SIS23d6OI=" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="Book" href="/favicon.ico" /></head>
<body>
<form id="form1" name="form1" method="post" action="/register.go?action=gotoRegPage">
<p>用户名:
<label>
<input type="text" name="userName" />
</label>
</p>
<p>密码:
<label>
<input type="text" name="password1" />
</label>
</p>
<p>确认密码:
<label>
<input type="text" name="password2" />
</label>
</p>
<p>昵称:
<label>
<input type="text" name="nikeName" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
</form>
</body>
</html>控制器文件:
.....
ROUser rOUser = new ROUser();
rOUser.setNikename(nikeName);
rOUser.setPassword(password);
rOUser.setUserName(userName);
int isSave = userService.addNewUser(rOUser);
......POUser.xml 文件:
......
<insert id="saveUser" parameterClass="poUser">
insert into
tb4user(user_id,user_name,nikename,password)
values(#userId#,#userName#,#nikename#,#password#)
</insert>不知我这样描述得清楚没?这个问题困扰了我好多天,本地运行得好好的,但放到租用的虚拟服务器上就出问题,各位好心的大哥大姐帮忙看看怎么解决。
user=root
password=123456
minPoolSize=5
maxPoolSize=50注册页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>注册页面</title>
<meta http-equiv="keywords" content="" />
<meta http-equiv="description" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="verify-v1" content="Bc3Pi9T36s2ZJxgj0Kycbd1JFj93kMytn2SIS23d6OI=" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="Book" href="/favicon.ico" /></head>
<body>
<form id="form1" name="form1" method="post" action="/register.go?action=gotoRegPage">
<p>用户名:
<label>
<input type="text" name="userName" />
</label>
</p>
<p>密码:
<label>
<input type="text" name="password1" />
</label>
</p>
<p>确认密码:
<label>
<input type="text" name="password2" />
</label>
</p>
<p>昵称:
<label>
<input type="text" name="nikeName" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
</form>
</body>
</html>控制器文件:
.....
ROUser rOUser = new ROUser();
rOUser.setNikename(nikeName);
rOUser.setPassword(password);
rOUser.setUserName(userName);
int isSave = userService.addNewUser(rOUser);
......POUser.xml 文件:
......
<insert id="saveUser" parameterClass="poUser">
insert into
tb4user(user_id,user_name,nikename,password)
values(#userId#,#userName#,#nikename#,#password#)
</insert>不知我这样描述得清楚没?这个问题困扰了我好多天,本地运行得好好的,但放到租用的虚拟服务器上就出问题,各位好心的大哥大姐帮忙看看怎么解决。
http://topic.csdn.net/u/20110110/16/807f9b6b-3a50-45fc-98f6-c8aea2ab14a1.html
例如maiba.us这个免费的地方,就不支持utf-8,不管你怎么设置,默认显示的都是gb2312,就算是utf-8的东西,在他那里都变成了gb2312
POUser user = new POUser();
user.setNikename(new String("小米".getBytes("iso8859-1"),"utf8"));
this.getSqlMapClient().insert("saveUser", user);
在数据库中"小米"还是变成"??"
<filter>
<filter-name>encodingFilter</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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
jdbcUrl=jdbc:mysql://127.0.0.1:3306/newdb?useUnicode=TRUE&characterEncoding=utf8就可以了,细仔看看有什么差别没,“&”改成“&”,唉,一个符号引发的悲剧呀。