IBM Worklight - 来自webservice的数据响应中的错误字符集/编码 [英] IBM Worklight - Error charset/encoding in data response from webservice

查看:301
本文介绍了IBM Worklight - 来自webservice的数据响应中的错误字符集/编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IBM worklight开发混合应用程序。在本地开发环境中,一切正常。

I use IBM worklight to develop a hybrid app. In the local development environment everything is OK.

我在部署到外部服务器(使用 oracle 数据库)时遇到问题。我的应用程序通过适配器调用Web服务,但响应中的数据有编码问题:unicode字符无法正确显示。我将字符集(在适配器调用函数中)更改为 ISO-8859-1 ,然后unicode字符显示正确。

I have an issue when I deploy to an external server (with oracle database). My app calls a webservice via an adapter, but the data in the response has an encoding problem: unicode characters do not display correctly. I changed the charset (in the adapter invoke function) to ISO-8859-1, and then unicode characters display correctly.

function invokeWebService(body, headers, soapAction) {
var input = {
    method : 'post',
    returnedContentType : 'xml',
    path : '/transaction/services/TransactionService.TransactionServiceHttpSoap11Endpoint/',
    body: {
        content : body.toString(),
        contentType : 'text/xml; charset=ISO-8859-1'
    }
};

//Adding custom HTTP headers if they were provided as parameter to the procedure call
//Always add header for SOAP action 
headers = headers || {};
if (soapAction != 'null')
    headers.SOAPAction = soapAction;
input['headers'] = headers;

return WL.Server.invokeHttp(input);
}

然而,当我想将数据插入数据库使用默认字符集 UTF-8 )。数据已插入错误字符集(因为 ISO-8859-1 )。

However the problem then happens again when I want to insert data to database (oracle with default charset UTF-8). The data has been inserted with error charset (because ISO-8859-1).

如何获取数据响应正确的字符集使用UTF-8而不必从网络服务更改编码?

或使用ISO-8859-1字符集获取数据,数据库与UTF-8?

推荐答案

@idan Adar这是一个解决方案的系统使用Liberty但我使用tomcat。我找到了解决方案。只需更改Tomcat的默认字符集:

@Idan Adar It's a solution for system use Liberty but I use tomcat. I have found solution for it. Just change Tomcat's default charset:

set "JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF8"

在Windows 中更改Tomcat的Charset.defaultCharset

Change Tomcat's Charset.defaultCharset in windows

这篇关于IBM Worklight - 来自webservice的数据响应中的错误字符集/编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆