解决java编程乱码问题

来源:互联网 发布:出租车计价软件 编辑:程序博客网 时间:2024/05/16 05:31

处理乱码问题

1、规范数据库和页面所有编码统一为一种例如utf-8

2、hibernate连接数据库设置连接编码

<session-factory>
   <property name="connection.url">
   jdbc:mysql://127.0.0.1:3306/leaveword?useUnicode=true&amp;characterEncoding=utf-8
  </property>

</session-factory>

3、提交数据前进行编码

String userName = new String (userName.getBytes("iso-8859-1","utf-8"))

或者加入过滤器

加入过滤器步骤

 

1)写一个过滤器类

 

2)配置web.xml

 

 

原创粉丝点击