从Broker DB中获取动态组件时的字符编码问题 - Tridion,Oracle,JSP

时间:2012-11-23 17:29:02

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

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

我有一个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数据库(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 

以前有没有其他人来过这样的例子。看起来DB存储,与DB的连接或cp.getContent()存在问题;方法

如果您有任何其他问题,请与我们联系。

此致 克里斯

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

字符编码问题可能非常复杂。在你的情况下,由于你已经做了很多调查,我会开始检查jsp文件是否有正确的页面编码集:

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