6

从代理数据库查看动态内容时,我遇到了字符编码问题。

我有一个 scriptlet,它调用代理 DB 以生成 XML 字符串,然后由 XSL 解析。

调试此问题时,我已经剥离了我的代码,脚本现在看起来像:

.....

strOutput= "<xml>";
ComponentPresentationFactory cpf = new ComponentPresentationFactory(PublicationID);

for (int i =0; i < itemURIs.length; i++)
{
ComponentPresentation cp = cpf.getComponentPresentation(itemURIs[i], strComponentTemplateURI);  
      if(cp != null){
        String content = "";
        content = cp.getContent();
        strOutput += content;
      }
}
strOutput+= "</xml>";

......

当我手动覆盖此代码并在代码中手动设置 xml 字符串内容时,数据将正确显示在屏幕上,即:

.....

strOutput= "<xml>";
ComponentPresentationFactory cpf = new ComponentPresentationFactory(PublicationID);

for (int i =0; i < itemURIs.length; i++)
{
ComponentPresentation cp = cpf.getComponentPresentation(itemURIs[i], strComponentTemplateURI);  
      if(cp != null){
        String content = "<xml><dynamicContent><subtitle><![CDATA[Außenbeleuchtung]]></subtitle></dynamicContent></xml>";
        strOutput += content;
      }
}
strOutput+= "</xml>";

......

组件使用输出格式设置为“XML 格式”的 CT 发布到内容代理 DB。

发布目标设置为目标语言:JSP 和默认代码页:Unicode UTF-8

当我使用此 CT 预览内容时,数据会正确显示:

<dynamicContent>
    <tcm_id>tcm:345-23288</tcm_id>
    <title><![CDATA[LED Road R250 - Maximum LED performance for street and highway illumination]]></title>
    <subtitle><![CDATA[Außenbeleuchtung ]]></summary>
</dynamicContent>

通过模板生成器进行预览时也是如此。

Broker DB 是一个 Oracle DB(Oracle Database 11g Enterprise Edition Release 11.2.0.2.0),我检查了字符集

SQL> select * from v$nls_parameters where parameter like '%CHARACTERSET%'; 

PARAMETER VALUE 

NLS_CHARACTERSET UTF8 
NLS_NCHAR_CHARACTERSET UTF8 

有没有其他人遇到过这样的例子。看起来数据库存储、与数据库的连接或 cp.getContent(); 存在问题 方法。

任何帮助将不胜感激,如果您有任何其他问题,请告诉我。

问候,克里斯

4

2 回答 2

1

看看这篇讨论解决编码问题的方法的文章:http: //elenaserghie.blogspot.ca/2012/01/7-clues-to-solve-character-encoding.html

于 2012-11-23T17:55:29.900 回答
0

字符编码问题可能相当复杂。在您的情况下,由于您已经进行了相当多的调查,我将开始检查 jsp 文件是否具有正确的页面编码集:

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
于 2012-11-23T17:52:32.953 回答