JDK142_p6 - non-ascii encoding problem?
Sergei Komarov
sk at pressevent.com
Tue May 25 10:17:04 PDT 2004
Thank you for your suggestions. It turns out that the issue is not
FreeBSD-specific: I was able to replicate it on Solaris. In the end, I
opted for implementing the transcoding in a custom taglib and upgrading
the app.
Thank you,
Sergei Komarov
-----Original Message-----
From: Panagiotis Astithas [mailto:past at noc.ntua.gr]
Sent: Friday, May 21, 2004 2:55 AM
To: Sergei Komarov
Cc: freebsd-java at freebsd.org
Subject: Re: JDK142_p6 - non-ascii encoding problem?
Sergei Komarov wrote:
> Hello,
>
> I'm running FreeBSD 4.9-STABLE, jdk1.4.2_p6 and Tomcat 4.1.30 or
> 5.0.24 and keep having a problem with non-Latin1 characters output by
> JSPs. This problem seems to be specific to FreeBSD as it doesn't occur
> on Windows (I'm testing Solaris as well).
>
> A JSP receives a request attribute containing a string of non-Latin1
> characters (Cyrillic Windows, Simplified Chinese gb2312, etc.)
>
> When the string is output within a page via c:out, struts bean:write
> or <%=name%>, JspWriter converts all non-Latin1 chars to '?'.
>
> I can correct it with either of the following tricks, but the
> application is too big to replicate them in all JSPs: <%@page
> language="java"
> contentType="text/html;charset=gb2312"
> import= "java.nio.charset.*,
> java.nio.CharBuffer,
> java.nio.ByteBuffer"
> %>
> <%
> String orig = (String) request.getAttribute("original"); String
> encoded = new String(orig.getBytes("ISO-8859-1"),"gb2312");
> %>
> ...
> <%= encoded %>
> ...
> <%
> Charset gb2312 = Charset.forName("gb2312");
> Charset iso = Charset.forName("ISO-8859-1");
> CharBuffer cb = CharBuffer.wrap(orig);
> ByteBuffer bb = iso.encode(cb);
> %>
> ...
> <%= gb2312.decode(bb) %>
>
> Am I missing something in the configuration of FreeBSD and JDK?
>
> I tried setting
> LANGUAGE zh_CN
> LANG zh_CN.gb2312
> LC_TYPE zh_CN
> LC_ALL zh_CN
> MM_CHARSET gb2312
>
> In /etc/profile etc., but to no avail. Perhaps someone knows the
> solution to this?
You could try adding the following to the default class in
/etc/login.conf:
:charset=zh_CN.GB2312:\
:lang=zh_CN.GB2312:\
and then doing "cap_mkdb /etc/login.conf".
You could also have just mis-spelled the locale.
Cheers,
--
Panagiotis Astithas
Electrical & Computer Engineer, PhD
Network Management Center
National Technical University of Athens, Greece
More information about the freebsd-java
mailing list