简体   繁体   English

如何向SmartGWT应用程序添加UTF-8支持

[英]How to add UTF-8 support to SmartGWT application

I am implemtnting a smartgwt application for a client that need support to utf-8 language(RTL). 我正在为需要支持utf-8语言(RTL)的客户端实现smartgwt应用程序。 Now I have a listgrid which takes in persian text and when i try to save it to my mssql 2008 database, it saves it like this ????? 现在,我有了一个接受波斯文字的listgrid,当我尝试将其保存到我的mssql 2008数据库中时,它像这样保存它? instead of the perisan text itself. 而不是Peransan文字本身。 In my database table I have defined the col type as nvarchar which is the requirement for saving utf-8. 在我的数据库表中,我已将col类型定义为nvarchar,这是保存utf-8的要求。 but the problem is smartgwt is not sending the text in proper format. 但是问题是smartgwt没有以正确的格式发送文本。 I have put this in my html file 我已经把它放在我的html文件中

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

In the developer Console when I look into the RPC tab. 在开发人员控制台中,当我查看“ RPC”选项卡时。 I see the DSREquest is being sent in UTF-8 format but in the DSResponse and in my db I get this ??????. 我看到DSREquest以UTF-8格式发送,但是在DSResponse和我的数据库中,我得到了这个??????。 In my database table I have defined the col type as nvarchar which is the requirement for saving utf-8. 在我的数据库表中,我已将col类型定义为nvarchar,这是保存utf-8的要求。 but the problem is smartgwt is not sending the text in proper format into the db. 但是问题是smartgwt没有将正确格式的文本发送到数据库中。 can somebody help me to get this correct. 有人可以帮助我纠正这个问题吗?

In the console I see everything correct 在控制台中,我看到一切正确

=== 2015-04-22 12:45:25,929 [9-27] INFO PoolManager - [builtinApplication.importExcelDS_add] SmartClient pooling started for 'SQLServer' objects === 2015-04-22 12:45:25,929 [9-27]信息PoolManager-[builtinApplication.importExcelDS_add]已为“ SQLServer”对象启动SmartClient池

=== 2015-04-22 12:45:25,929 [9-27] DEBUG PoolableSQLConnectionFactory - [builtinApplication.importExcelDS_add] Initializing SQL config for 'SQLServer' from system config - using DriverManager: net.sourceforge.jtds.jdbc.Driver === 2015-04-22 12:45:25,929 [9-27]调试PoolableSQLConnectionFactory-[builtinApplication.importExcelDS_add]从系统配置中初始化“ SQLServer”的SQL配置-使用DriverManager:net.sourceforge.jtds.jdbc.Driver

=== 2015-04-22 12:45:25,929 [9-27] DEBUG PoolableSQLConnectionFactory - [builtinApplication.importExcelDS_add] net.sourceforge.jtds.jdbc.Driver lookup successful === 2015-04-22 12:45:25,929 [9-27]调试PoolableSQLConnectionFactory-[builtinApplication.importExcelDS_add] net.sourceforge.jtds.jdbc.Driver查找成功

=== 2015-04-22 12:45:25,929 [9-27] DEBUG PoolableSQLConnectionFactory - [builtinApplication.importExcelDS_add] DriverManager fetching connection for SQLServer via jdbc url jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbilling;useUnicode=true;characterEncoding=UTF-8;sendStringAsUnicode=true;User=teoit;Password=seop === 2015-04-22 12:45:25,929 [9-27]调试PoolableSQLConnectionFactory-[builtinApplication.importExcelDS_add] DriverManager通过jdbc url jdbc:jtds:sqlserver:// localhost:1433;获取SQLServer的SQLServer连接; DatabaseName = dbilling; useUnicode = true; characterEncoding = UTF-8; sendStringAsUnicode = true; User = teoit; Password = seop

=== 2015-04-22 12:45:25,929 [9-27] DEBUG PoolableSQLConnectionFactory - [builtinApplication.importExcelDS_add] Passing JDBC URL only to getConnection === 2015-04-22 12:45:25,929 [9-27]调试PoolableSQLConnectionFactory-[builtinApplication.importExcelDS_add]仅将JDBC URL传递给getConnection

=== 2015-04-22 12:45:25,999 [9-27] INFO SQLDriver - [builtinApplication.importExcelDS_add] Executing SQL update on 'SQLServer': INSERT INTO sales (available, productMth, productName, productYr) VALUES (NULL, NULL, 'به آسا اماکن ۸ ٪ - ۴ لیتر - محلول ضد عفونی کننده', NULL) === 2015-04-22 12:45:25,999 [9-27]信息SQLDriver-[builtinApplication.importExcelDS_add]在'SQLServer'上执行SQL更新:插入销售(可用,productMth,productName,productYr)值(空, NULL,'بهآسااماکن۸-%لیتر-محلولضدعفونیکننده',NULL)

The only thing that is missing is the N which should have been there before the utf-8 string. 唯一缺少的是N,它应该在utf-8字符串之前就已经在那里。 like so 像这样

INSERT INTO sales (available, productMth, productName, productYr) VALUES               
(NULL, NULL, N'به آسا اماکن ۸ ٪ - ۴ لیتر - محلول ضد عفونی کننده', NULL)
can somebody help me to get this correct.

When I had problem with Russian characters I added this code in constructor of my data source: 当我对俄语字符有疑问时,我在数据源的构造函数中添加了以下代码:

DSRequest dsRequest = new DSRequest();
dsRequest.setContentType("application/json; charset=utf-8");
setRequestProperties(dsRequest);

I'm using REST DataSource with JSON format. 我正在使用JSON格式的REST DataSource。

OK, got it to work and for peopel who want to get the answer to this problem. 好的,让它起作用并适合希望获得该问题答案的人。 I got this working by assigning the type of the field as ntext. 我通过将字段的类型分配为ntext来完成此工作。 so here is datasource file and the field called productName where I have my UTF-8 text 所以这是数据源文件和名为productName的字段,其中有我的UTF-8文本

<DataSource ID="importExcelDS" serverType="sql" tableName="sales">
<fields>
    <field name="importID" type="sequence" hidden="true" primaryKey="true" />
    <field name="productName" title="Product Name" type="ntext" />
    <field name="productMth" title="product Mth" type="int" />
    <field name="productYr" title="product Yr" type="int" />
    <field name="available" title="Quantity" type="int" />
</fields>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM