【问题标题】:Character encoding issues when getting dynamic components out of a Broker DB - Tridion , Oracle , JSP从 Broker DB 中获取动态组件时的字符编码问题 - Tridion、Oracle、JSP
【发布时间】:2012-11-12 01:56:00
【问题描述】:

我在查看代理数据库中的动态内容时遇到字符编码问题。

我有一个 scriptlet,它调用代理数据库以生成 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 将组件发布到内容代理数据库。

发布目标设置为目标语言: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 数据库 11g 企业版版本 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(); 存在问题方法。

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

问候, 克里斯

【问题讨论】:

  • 从 SQLPlus 中检索到的内容是什么样的?您是否尝试将日志级别设置为调试并检查 getContent 调用中的任何编码问题?您是否尝试过使用 ComponentPresentationAssembler 而不是 ComponentPresentationFactory?
  • 您好 Nuno,我通过 Oracle DB 管理器查看了内容,查看时没有编码问题,但这可能是因为查看器正在处理编码。我刚刚使用 ComponentPresentationAssembler 而不是 ComponentPresentationFactory 实现了我的代码,它具有完全相同的最终结果。

标签: tridion tridion-2011 tridion-content-delivery


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
    

    【讨论】:

    • 您好 Qurijn,我已将此添加到 scriptlet 代码中,但它并没有改变我看到的问题。感谢您的快速响应
    • 您确定您的 CP(cd_storage_conf.xml 中的 typeMapping=ComponentPresentation)已发布到数据库中吗?
    猜你喜欢
    • 2020-09-26
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多