dev@glassfish.java.net

Re: encoding in JSP Documents - JDK6 I18N Issue??

From: Krishnamohan Meduri <Krishna.Meduri_at_Sun.COM>
Date: Tue, 07 Nov 2006 11:04:17 -0800

Jan,


Jan Luehe wrote On 11/06/06 18:26,:
> Krishna,
>
> Krishnamohan Meduri wrote On 11/06/06 17:23,:
>
>
>>Hi,
>>
>>Glassfish with JDK6 produces undesired results (with some characters
>>messed up) for the attached JSP Document.
>>The same produces the desired results with JDK5.
>>
>>Is this any known issue in JDK6? If so, Could somebody pls give me the
>>details?
>>
>>
>
>
> No details, but here's a related issue:
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6473140
> ("getCharacterEncoding() did not return the default-charset on
> windows2003(JDK 6, AS90PE)")
>
> that was filed against GlassFish.
>
> I've done some initial investigation, and it looks like creating a
> String, using the String constructor that takes a charsetName, throws
> an UnsupportedEncodingException when specifying "Shift_JIS" as the
> encoding on Windows (we use the String constructor that takes a
> charsetName argument as a test to see if the encoding passed to
> ServletRequest.setCharacterEncoding() is valid and supported by the
> runtime). I've asked the submitter to confirm.
>
> Do you see any UnsupportedEncodingException in your server log? Also,
> do you see this problem on Windows only?

This appears to be a different problem.
I *don't* see any exception. I can see the problem on Glassfish on
*Solaris* also.
To reproduce, all you need to do is have this JSP document in a web app
and send a request to it. While switching JDK version, just make sure
that you remove generated classes from generated folder.
On glassfish, I got the output attached (jdk5.out.as and jdk6.out.as).
I took out just oneline (1st line from 2nd para) from both the files and
ran xxd. I attached the output. As you can see, a few characters are
getting messed up.

I wanted to know if it is any known JDK6 issue before I start debugging.

-Krishna.
>
>
> Jan
>
>
>
>>Thanks,
>>-Krishna.
>>
>>
>>------------------------------------------------------------------------
>>
>><?xml version="1.0" encoding="big5"?>
>><!--
>> @author James Cai, for I18N feature in JSP 2.0 in XML
>>
>> Configuration as the following:
>> Syntax pageEncoding contentType XML-prolog
>> XML big5 gb2312 -
>>-->
>>
>><jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
>>version="2.0">
>><jsp:directive.page contentType="text/html; charset=gb2312" />
>><jsp:text><![CDATA[<HTML>
>><HEAD>
>> <TITLE>I18N TEST JSP2.0</TITLE>
>></HEAD>
>>
>><BODY>
>>
>><FONT SIZE='+3'>
>>
>><CENTER>
>>
>><BR/>
>>
>>
>><H1>Test Name: XML8-gb </H1>
>>
>><BR/>
>><BR/>
>><TABLE BORDER='1'>
>><TR><TH>Language</TH><TH>Charset</TH></TR>
>><TR><TD>Chinese</TD><TD>gb2312</TD></TR>
>></TABLE>
>>
>><BR/>
>>
>>The following is Chinese character with gb2312 charset:
>>
>><BR/><BR/>
>>
>>¾©±¨ÍøÑ¶£¨¼ÇÕß¡¡¶¡ÕØÎÄ£©´Ó½ñÌ쿪ʼ£¬ÃÀ¹úÂéÊ¡Àí¹¤Ñ§ÔºË¹Â¡¹ÜÀíѧԺÓëÇ廪´óѧ¾­¹ÜѧԺ¡¢¸´µ©´óѧ¹ÜÀíѧԺ¡¢Ïã¸ÛÁëÄÏ´óѧ
>> ΪºÏ×÷ÅàÑø¹ú¼ÊMBA£¬ÔÚÏã¸ÛÕÙ¿ª¹ËÎÊίԱ»á»áÒé¡£¼ÇÕß×òÌì´ÓÇ廪´óѧ»ñϤ£¬×÷Ϊ¸÷×Ô¹ú¼Ò×î¶¥¼âµÄÉÌѧԺ֮һµÄÇ廪´óѧ
>> ¾­¹ÜѧԺÓëÂéÊ¡Àí¹¤Ñ§ÔºË¹Â¡¹ÜÀíѧԺ£¬ÔÚÔ²ÂúÍê³ÉÁ˵ÚÒ»¸öÎåÄêÖÜÆÚµÄºÏ×÷Ö®ºó£¬ÒѾ­¾ö¶¨´Ó½ñÄêÆðÐøÇ©ÎåÄêµÄºÏ×÷ÏîÄ¿£¬Ë«·½
>> ´Ó1500ÃûÉêÇëÕßÖÐÑ¡°Î³öµÄÐÂÒ»Åú120ÃûºÏ×÷ÅàÑøµÄ¹ú¼ÊMBAѧԱ£¬¼´½«ÓÚ½ñÄê9Ô½øÇ廪´óѧ¡£
>>
>> Ç廪´óѧ¾­¹ÜѧԺԺ³¤ÕÔ´¿¾ù×òÌìÔÚ½ÓÊܼÇÕ߲ɷÃʱ±íʾ£¬Ç廪×Ô1996ÄêÓëÂéÊ¡Àí¹¤ºÏ×÷ÒÔÀ´£¬ÖÁ½ñÒÑÅàÑøÁËÈýÆÚ¹²100ÓàÃû¹ú
>> ¼ÊMBAѧԱ£¬ÕâЩ±ÏҵѧԱһ°ã¶¼È¥Á˹úÄÚÍâµÄ¿ç¹úÆóÒµºÍ×éÖ¯£¬Ò»Ö±¹©²»Ó¦Çó£¬ÓеÄÔڶ̶ÌÁ½ÈýÄêÄÚ£¬¾ÍÒѾ­×øµ½ÁËCEO
>> µÄλÖã»ÔÚºÏ×÷ÆÚ¼ä£¬Ç廪ÏȺóÅɳö20ÓàÃû½Ìʦ£¬ÔÚ˹¡¾­¼Ã¹ÜÀíѧԺѧϰ¡£ÕÔ´¿¾ùÔº³¤»¹Í¸Â¶£¬ÔÚ¹ýÈ¥µÄºÏ×÷ÖУ¬Ç廪·½ÃæµÄÖ÷
>> Òª¾«Á¦¼¯ÖÐÔÚÁ˱ØÐ޿εĽ¨Éè·½Ãæ£¬ÔÚµÚ¶þ¸öÎåÄêµÄºÏ×÷ÖУ¬·ÅÔÚÑ¡Ð޿η½ÃæµÄ¾«Á¦»á¶àһЩ¡£Í¬Ê±£¬ÕâÖÖÀàËÆÓÚ¼¼ÊõתÈõÄÄ£
>> ʽ£¬ÔÚ¾­ÀúÁËÎåÄêµÄºÏ×÷ºóÒѾ­ÊµÏÖÁ˽«¹úÍâ³ÉÊìµÄMBAÅàÑøÄ£Ê½ÒÆÖ²µ½¹úÄÚµÄÄ¿±ê¡£
>>
>> ×òÌìר³Ìµ½±±¾©²Î¼ÓÇ廪2001½ì¹ú¼ÊMBA±ÏÒµµäÀñµÄ˹¡¹ÜÀíѧԺǰÈÎÔº³¤¡¢ÖøÃû¹ú¼Ê¾­¼Ãѧ¼Ò˹Èô½ÌÊÚÒ²ÈÏΪ˫·½Ç°ÎåÄê
>> µÄºÏ×÷·Ç³£³É¹¦£¬ËûÔø¾­Í¨¹ýÊÓÆµ»áÒéµÄ·½Ê½¡°Ãæ¶ÔÃæ¡±µØÎªÇ廪¹ú¼ÊMBAѧԱÊÚ¹ý¿Î£¬ËûÈÏΪÖйúµÄ¹ú¼ÊMBAÏîÄ¿ÒÔ¼°Åà
>> Ñø³öµÄѧԱ¶¼²»±ÈÃÀ¹ú²î£¬Î©Ò»µÄȱµãÔÚÓÚѧÉúµÄ³É·Öȱ·¦¹ú¼ÊÐÔ£¬ÔÚÃÀ¹ú´óÔ¼40£¥µÄѧԱÀ´×ÔÓÚÆäËû²»Í¬µÄ¹ú¼Ò£¬¶øÔÚÖйú¼¸ºõ
>> ÊÇÇåһɫµÄ¹úÄÚѧԱ¡£
>>
>></CENTER>
>><BR/>
>><BR/>
>>]]></jsp:text>
>><jsp:text>CharacterEncoding:
>></jsp:text>
>><jsp:expression>response.getCharacterEncoding()</jsp:expression>
>><jsp:text>&lt;BR/&gt;</jsp:text>
>><jsp:text><![CDATA[
>></body>
>></html>
>>]]></jsp:text>
>></jsp:root>
>>
>>
>>------------------------------------------------------------------------
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>


Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HTTP/1.1 200 OK
X-Powered-By: JSP/2.1
Set-Cookie: JSESSIONID=fd795e713596e06cc9d6dcca9f0e; Path=/i18n
Content-Type: text/html;charset=gb2312
Content-Length: 1683
Date: Tue, 07 Nov 2006 00:35:46 GMT
Server: Sun Java System Application Server Enterprise Edition 9.1
Connection: close

<HTML>
<HEAD>
   <TITLE>I18N TEST JSP2.0</TITLE>
</HEAD>

<BODY>

<FONT SIZE='+3'>

<CENTER>

<BR/>


<H1>Test Name: XML8-gb </H1>

<BR/>
<BR/>
<TABLE BORDER='1'>
<TR><TH>Language</TH><TH>Charset</TH></TR>
<TR><TD>Chinese</TD><TD>gb2312</TD></TR>
</TABLE>

<BR/>

The following is Chinese character with gb2312 charset:

<BR/><BR/>

?ã°?ͱ¨×ĺë´??ì¤?¨ØÖ²Ì¤?ôË?¨Û?±×????ã¦ÛïÙ¦???ã¦Ûï?§îòäÎã¦??ã¦Ûï?ÝâͲäÎã¦??ã¦Ûï?????äÎã¦
                        ?´Å???±×?MBA¨Û????ôËàÐ?????ìï?ĺë´??Ö²§îòäÎã¦??¨Û??¹ò?±×Ä£???Ç»?ã¦Ûï??Ç»§îòäÎã¦
                        ??ã¦Ûï?????ã¦ÛïÙ¦???ã¦Ûï¨Û?Ûú??????¶å???¤ÖÇ»´Å???¨Û??éÔÓçֲ̤?¤ìÛÁ¥ï??Ç»´Å??õ·¨Û?Ô´
                        Ö²1500ÃÒ?¢Ûë´?í¥ÄäµÌÇ»Úë??120ÃÒ´Å???Ç»±×?MBAã¦?¨Û?εôÀ̤?9??§îòäÎã¦?

                        §îòäÎã¦??ã¦ÛïÛïÐï?Ôøì¨?????ĺë´Á£??Ͱ?¨Û§îò?1996??????´Å??¶®¨Û?̤??????¤Ö?100?ÃÒ±×
                        ?MBAã¦?¨Û??¾È?ã¦??à¨??ÃñÙ¦???Ç»?±×¤ï?î£??¨Û??¶¦ÏéÜí¢Å¨Ûô¬Ç»?ɵɵ?????¨Ûí¬???ÉÆ?CEO
                        Ç»?Àë??´Å?¤Ö?¨Û§îòçæ??µÌ20?ÃÒ??¨Û?Ù¦?????ã¦Ûïã¦???Ôøì¨ÛïÐï???¨Û???ÈÓ????±Â?ðÞ????
                        áû?ÊíĦ???õúµ³?Ç»±ì?Ô´?¨Û???¶å??Ç»´Å??¨Û??í¥µ³?Ô´?Ç»?Êí?ËÃ???°¹?¨Û?óÑ?Ù°ôÀ´é??????
                        ?¨Û??????Ç»´Å????æ¡??ε±×???Ç»MBA??Ò«?ðäí÷ÉÆ±×?Ç»õ·è÷?

                        ???×îÉÆ¿Ø???§îò2001Ȥ±×?MBA¾È?ή?ǻ٦???ã¦Ûï¥ö??Îõ³ó£Èõó?±×???ã¦Ä£Ù¦??ê¾?óÐ???°ýÄä??
                        Ç»´Å??¶¼?÷Õ¨ÛÛæ?????¤±?ìïǻԴ?¡ù?ÇÚ?¡ì??§îò±×?MBAã¦????¨ÛÛæ??¿Ï??Ç»±×?MBA?õ·???
                        ?µÌÇ»ã¦??ÏéÏÆ?±×´¬¨Û??Ç»?½Ó???´²?Ç»?ìã?Åõ´Ë???¨Û??±×äÎ?40¨ÔÇ»ã¦?¶®?ôÀ¤àÛæÏ鰹ǻ±×Ä£¨Û???±×??
                        ?§î?¼¿Ç»±×?ã¦??

</CENTER>
<BR/>
<BR/>
CharacterEncoding:
gb2312<BR/>
</body>
</html>
Connection to localhost closed by foreign host.

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HTTP/1.1 200 OK
X-Powered-By: JSP/2.1
Set-Cookie: JSESSIONID=ff5f3f1b612f80532e8eadfa11e8; Path=/i18n
Content-Type: text/html;charset=gb2312
Content-Length: 1678
Date: Tue, 07 Nov 2006 01:08:57 GMT
Server: Sun Java System Application Server Enterprise Edition 9.1
Connection: close

<HTML>
<HEAD>
   <TITLE>I18N TEST JSP2.0</TITLE>
</HEAD>

<BODY>

<FONT SIZE='+3'>

<CENTER>

<BR/>


<H1>Test Name: XML8-gb </H1>

<BR/>
<BR/>
<TABLE BORDER='1'>
<TR><TH>Language</TH><TH>Charset</TH></TR>
<TR><TD>Chinese</TD><TD>gb2312</TD></TR>
</TABLE>

<BR/>

The following is Chinese character with gb2312 charset:

<BR/><BR/>

?ã°?ͱ¨×ĺë´??ì¤?¨ØÖ²Ì¤?ôË?¨Û?±×????ã¦ÛïÙ¦???ã¦Ûï?§îòäÎã¦??ã¦Ûï?ÝâͲäÎã¦??ã¦Ûï?????äÎã¦
                        ?´Å???±×?MBA¨Û????ôËàÐ?????ìï?ĺë´??Ö²§îòäÎã¦??¨Û??¹ò?±×Ä£???Ç»?ã¦Ûï??Ç»§îòäÎã¦
                        ??ã¦Ûï?????ã¦ÛïÙ¦???ã¦Ûï¨Û?Ûú??????¶å???¤ÖÇ»´Å???¨Û??éÔÓçֲ̤?¤ìÛÁ¥ï??Ç»´Å??õ·¨Û?Ô´
                        Ö²1500ÃÒ?¢Ûë´?í¥ÄäµÌÇ»Úë??120ÃÒ´Å???Ç»±×?MBAã¦?¨Û?εôÀ̤?9??§îòäÎã¦?

                        §îòäÎã¦??ã¦ÛïÛïÐï?Ôøì¨?????ĺë´Á£??Ͱ?¨Û§îò?1996??????´Å??¶®¨Û?̤?????¤Ö?100?ÃÒ±×
                        ?MBAã¦?¨Û??¾È?ã¦??à¨???±×??Ç»?±×¤ï?î£??¨Û??¶¦ÏéÜí¢Å¨Ûô¬Ç»?ɵɵ????¨Ûí¬???ÉÆ?CEO
                        Ç»?Àë??´Å?¤Ö?¨Û§îòçæ??µÌ20?ÃÒ??¨Û?Ù¦?????ã¦Ûïã¦???Ôøì¨ÛïÐï???¨Û???Ç»´Å??¨Û§îòԴ?Ç»?
                        áû?ÊíĦ???õúµ³?Ç»±ì?Ô´?¨Û???¶å??Ç»´Å??¨Û??í¥µ³?Ô´?Ç»?Êí?ËÃ???°¹?¨Û?óÑ?Ù°ôÀ´é???ǻҫ
                        ?¨Û??????Ç»´Å????æ¡??ε±×???Ç»MBA??Ò«?ðäí÷ÉÆ±×?Ç»õ·è÷?

                        ???×îÉÆ¿Ø???§îò2001Ȥ±×?MBA¾È?ή?ǻ٦???ã¦Ûï¥ö?ÛïÐï??ÃÒ±×???ã¦Ä£Ù¦???çñ???Ô´¥ö??
                        Ç»´Å??¶¼?÷Õ¨ÛÛæ?????¤±?ìïǻԴ?¡ù?ÇÚ?¡ì??§îò±×?MBAã¦????¨ÛÛæ???±×Ç»±×?MBA?õ·???
                        ?µÌÇ»ã¦??ÏéÏÆ?±×´¬¨Û??Ç»?ÝÇ?ôÀã¦ãáÇ»?ìã?Ò¬±×??¨Û??±×äÎ?40¨ÔÇ»ã¦?¶®?ôÀ¤àÛæÏ鰹ǻ±×Ä£¨Û???±×??
                        ?§î?¼¿Ç»±×?ã¦??

</CENTER>
<BR/>
<BR/>
CharacterEncoding:
gb2312<BR/>
</body>
</html>
Connection to localhost closed by foreign host.

0000000: a7ee c3b2 e4ce e3a6 3f3f e3a6 dbef dbef ........??......
0000010: d0ef 3fd4 f8ec a83f 3f3f 3f3f c4ba ebb4 ..?....?????....
0000020: c1a3 3f3f cdb0 3fa8 dba7 eec3 b23f 3139 ..??..?......?19
0000030: 3936 3f3f 3f3f 3f3f b4c5 3f3f b6ae a8db 96??????..??....
0000040: 3fcc a43f 3f3f 3f3f 3fa4 d63f 3130 303f ?..??????..?100?
0000050: c3d2 b1d7 0a .....


0000000: a7ee c3b2 e4ce e3a6 3f3f e3a6 dbef dbef ........??......
0000010: d0ef 3fd4 f8ec a83f 3f3f 3f3f c4ba ebb4 ..?....?????....
0000020: c1a3 3f3f cdb0 3fa8 dba7 eec3 b23f 3139 ..??..?......?19
0000030: 3936 3f3f 3f3f 3f3f b4c5 3f3f b6ae a8db 96??????..??....
0000040: 3fcc a43f 3f3f 3f3f a4d6 3f31 3030 3fc3 ?..?????..?100?.
0000050: d2b1 d70a ....