zhaojun_2011
zhaojun_2011
2012-03-23 09:17

ssh2应用中统一设置成utf-8之后还会出现乱码问题?

  • spring
  • struts
  • 企业应用
  • hibernate

[size=medium]这里我使用的是struts2.0 Hibernate3.2 spring2.0 mysql5.0的配置,容器选择Tomcat6.0;

下面我们使用的是get的方式提交form表单所出现的情况:

前台页面使用:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="../documentTabSideBar.jsp"%>

...

涉及的表单:

<%@ include file="../title.jsp" %>
下面我先使用默认的get方式提交进行测试:


...

<%@ include file="../documentTabSideBar.jsp"%>这个页面的头部设置:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>





<%@ include file="css/css_all.css" %>

Action的代码:
public class AddDocumentCatalog extends ActionSupport
{
...
private String title;
...

@Override
public String execute() throws Exception
{
//这里我做了打印测试:
System.out.println(title);
...
this.service.saveDocumentCatalog(bean);

DAO层的实现:

public class DocumentCatalogDAOImpl extends HibernateDaoSupport implements DocumentCatalogDAO
{
public void saveDocumentCatalog(DocumentCatalog bean)
{
{
//这里我做了打印测试:
System.out.println(bean.getName());
this.getHibernateTemplate().save(bean);
}

Spring ioc配置:
destroy-method="close">

value="jdbc:mysql://localhost:3306/langsinoa?useUnicode=true&characterEncoding=UTF-8">...

到浏览器进行测试:输入“中文”两个字:

得到的请求url信息:

http://localhost:8080/oa/DocumentCatalog/addDocumentCatalog.action?type=1&parentId=-1&choice=directory&title=%E4%B8%AD%E6%96%87&title2=&description=&address=

这里的title就是乱码?

得到的Console显示:
??????
?????? //这里输出的测试结果!就是无法显示的!为什么?

firebug截图:

[img]http://dl.iteye.com/upload/attachment/0065/3366/f71dcfaf-a3b0-339d-8332-b28bb6c1c1f3.jpg[/img]

Hibernate:
select
max(id)
from
documentcatalog
Hibernate:
insert
into
langsinoa.documentcatalog
(name_, date_, flag_, authorId_, authorName_, type_, order_, content_, address_, parentId_, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

之后我将from的Method设置为post:
其他设置不变,出现的状况:

[img]http://dl.iteye.com/upload/attachment/0065/3368/1620f803-ce73-398d-b501-360e86bd1249.jpg[/img]

Console:

中文
中文
Hibernate:
insert
into
langsinoa.documentcatalog
(name_, date_, flag_, authorId_, authorName_, type_, order_, content_, address_, parentId_, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
虽然得到了中文,但是回到db:
mysql> select name_ from documentcatalog;
+--------------------+
| name_ |
+--------------------+
| one |
| 盲赂颅忙聳聡 |
| into! |
| 盲赂颅忙聳聡茂录聛 |
| 盲赂颅忙聳聡 |
| en |
| en |
| 涓枃 |
| 盲赂颅忙聳聡 |
| 盲赂颅忙聳聡 |
| 盲赂颅忙聳聡 |
| 涓枃 |
+--------------------+
12 rows in set (0.00 sec)
还是乱码:

db的编码设置方式:

首先是表:

| documentcatalog | CREATE TABLE documentcatalog (
id bigint(20) NOT NULL,
name_ varchar(50) default NULL,
...
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

下面是这个sb的default设置:

mysql> show variables like '%char%';
+--------------------------+-------------
-----+
| Variable_name | Value
|
+--------------------------+-------------
-----+
| character_set_client | utf8
|
| character_set_connection | utf8
|
| character_set_database | utf8
|
| character_set_filesystem | binary
|
| character_set_results | utf8
|
| character_set_server | utf8
|
| character_set_system | utf8
|
| character_sets_dir | C:\Program F
ets\ |

统一的是utf-8

我实在是没法了! 请大家帮忙解决一下! 谢谢!谢谢!

[/size]

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐