我把jsp xml java代码都设置成了utf-8, mysql中的表也是utf8.我在实现用户注册功能时出错了,Consumer这个类有个address属性,
网页提交表单后,显示注册成功,但是保存到Mysql数据库中的中文全部变成了“???”
从数据库读出也是“???”但是我在数据库中直接插入中文,然后代码中读出来,没有出错,还是中文。
这个到底是怎么回事啊--顺便问下在action中怎么设置request属性呢?DAO中保存用户方法如下public void save(Consumer u) {
log.debug("saving Consumer instance");
Transaction transaction= getSession().beginTransaction();
try {
Date date = new Date();
Timestamp theTime = new Timestamp(date.getTime());
u.setCreateTime(theTime);
u.setUpdateTime(theTime);
getSession().save(u);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
transaction.commit();
getSession().flush();
getSession().close();
}
}
网页提交表单后,显示注册成功,但是保存到Mysql数据库中的中文全部变成了“???”
从数据库读出也是“???”但是我在数据库中直接插入中文,然后代码中读出来,没有出错,还是中文。
这个到底是怎么回事啊--顺便问下在action中怎么设置request属性呢?DAO中保存用户方法如下public void save(Consumer u) {
log.debug("saving Consumer instance");
Transaction transaction= getSession().beginTransaction();
try {
Date date = new Date();
Timestamp theTime = new Timestamp(date.getTime());
u.setCreateTime(theTime);
u.setUpdateTime(theTime);
getSession().save(u);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
transaction.commit();
getSession().flush();
getSession().close();
}
}
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
struts.xml里加这句没?
这个问题不是java和tomcat的错误,是数据库本地配置的错误,其实你在安装的时候有个字符集选择的,
lz应该是直接默认的设置了吧,希望可以解决你的问题!
jdbc:mysql://localhost:/test?characterEncoding=gb2312;