2

I want to display Turkish characters stored in a PostgreSQL database in my JSP page I have included: <meta http-equiv="content-type" content="text/html;charset=utf-8" />.

I still can't see the actual Turkish characterset on screen. In the database, the string is stored as %C4%9F%C4%B1%C4%B0%C3%B6%C5%9F%C3%BC%C4%9F%C4%B0

When I fetch it from PostgreSQL using resultsetwrapperobject.getstring("columnname");, it will automatically convert it into a string like this: \304\237\304\261\304\260\303\266\305\237\303\274\304\

I want to know why this automatic conversion happen and how to stop this conversion.

4

1 回答 1

2

你能看看'resultsetwrapperobject'类的代码吗?可能是实现使用具有默认(或特殊)编码的缓冲读取器。

您可以使用

public String(byte bytes[], String charsetName)

用于转换字符串

final String charSet = "UTF8"; // or "ISO-8859-1"
String tSrt = resultsetwrapperobject.getstring("columnname");
tStr = new String(tStr.getBytes(),charSet);

您也可以尝试将 java 默认字段编码设置为 java 系统属性。

-Dfile.encoding=UTF8

于 2011-10-12T11:37:24.067 回答