5 Replies Latest reply on Jun 6, 2005 10:14 PM by caigao

    Encoding charset problem in client browser for RC2

    caigao

      hi, all.
      I am trying to translate the Resource file into Chinese, then i meet a question.

      My env is:
      windows xp (same problem as Redhat Linux AS 4.0)
      jdk1.5.0
      jboss 4.0.2
      jboss portal 2.0 RC2 src build
      hsqldb (mysql in redhat as4)

      i have trying to do every following changes:
      1.
      modify "core\src\resources\portal-core-war\WEB-INF\portal.xml"
      and change "<mime-type>text/html</mime-type>"
      to "<mime-type>text/html;charset=gb2312</mime-type>"

      2.
      same as above but changes to
      "<mime-type>text/html;charset=gbk</mime-type>"

      3.
      "<mime-type>text/html;charset=utf-8</mime-type>"

      4.
      modify "portlet\src\main\org\jboss\portal\portlet\impl\RenderResponseImpl.java"
      change to

       public void setContentType(String contentType)
       {
       String cs = contentType;
       int index = contentType.indexOf(';');
       System.out.println("-----------contentType:"+cs); //result is always "text/html"
       if (index != -1)
       {
       contentType = contentType.substring(0, index);
       }
       String responseContentType = resp.getContentType();
       System.out.println("--------responseContentType:"+responseContentType); //result is always "text/html"
       if (!responseContentType.equals(contentType))
       {
       throw new IllegalArgumentException("Content type not accepted");
       }
       //result.setContentType(contentType);
       result.setContentType("text/html;charset=gb2312");
       }
      


      5.
      modify theme index file: "core\src\bin\portal-core-war\nodesk\index.jsp"
      change ""
      to "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="gbk">"

      6.
      modify theme index file: "core\src\bin\portal-core-war\nodesk\index.jsp"
      change '<meta http-equiv="Content-Type" content="text/html" />'
      to '<meta http-equiv="Content-Type" content="text/html;charset=gbk" />'
      or '<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />'

      ================================
      i do these changes per time and make build clean build deploy and restart jboss AS.
      but every time the IE explorer give me the wrong answer like half top of the given image. I must select IE menu "view-->Encoding-->Chinese GB2312" to get correct result just like half bottom of the attach image.


      somebody can give the right answer? how can i do?

      thank you.

      [img]http://www.emig.cn/jbportalencodingerror.jpg[/img]

        • 1. Re: Encoding charset problem in client browser for RC2
          caigao
          • 2. Re: Encoding charset problem in client browser for RC2

            Hello Caigo,

            remove all your changes and just add the following line in org.jboss.portal.core.invocation.ContentTypeInterceptor in invoke(Invocation invocation) :

            
             // Set content type
             response.setContentType(mimeType);
            
             // <Add me>
             response.setCharacterEncoding("gb2312");
             // </Add me>
            
             // Continue invocation
             return invocation.invokeNext();
            
            


            We have not taken in account yet the charset and we should work on making that configurable easily.

            I think that using UTF-8 instead of gb2312 should work too as UTF-8 contains the chinese chars.

            • 3. Re: Encoding charset problem in client browser for RC2
              caigao

              thank you, julien@jboss.com.

              It's working!
              a little changes before you advice:
              The Resource_zh_CN.properties file must changed to UNICODE format by using:
              native2ascii --encoding gbk Resource_zh_CN.properties.native Resoutce_zh_CN.properties
              so even when i set
              response.setCharacterEncoding("gb2312");
              or
              response.setCharacterEncoding("utf-8");
              in file:
              org.jboss.portal.core.invocation.ContentTypeInterceptor
              it works fine.

              BUT, there has another problem about database encoding:
              before change CharacterEncoding the Character from database shows well, but incorrect after change it to "utf-8" or "gbk" just like this,

              Îå±Ê×ÖÐͼÆËã»úºº×ÖÊäÈë¼¼Êõ

              that is to say all chars in program show well but incorrect from database chars.

              what can i do then?

              thank you.

              • 4. Re: Encoding charset problem in client browser for RC2

                what do you mean by database chars ? coming from CMS ?

                • 5. Re: Encoding charset problem in client browser for RC2
                  caigao

                  Thank you for your reply, julien@jboss.com.

                  Mybe my english is not so good, my expression is sometimes not so clearly. I am so sorry.

                  After my test, it is both error in database chars and cms files after edit it.

                  In database chars come from jbp_users and jbp_forums chars

                  i have checked hsqldb i think it is wrong char utf8 converting like this:
                  content in database.log

                  INSERT INTO JBP_USERS VALUES(1,1,'admin','\u00b9\u00dc\u00c0\u00ed\u00d4\u00b1','\u00d1\u00ee','21232f297a57a5a743894a0e4a801fc3','admin@portal.com',NULL,'2005-06-07 09:22:50.684',TRUE,TRUE)
                  


                  it should be
                  INSERT INTO JBP_USERS VALUES(1,1,'admin','\u7ba1\u7406\u5458','\u6768','21232f297a57a5a743894a0e4a801fc3','admin@portal.com',NULL,'2005-06-07 09:22:50.684',TRUE,TRUE)
                  


                  the attached image shows the errors.

                  [img]http://www.emig.cn/encodingerr.jpg[/img]
                  http://www.emig.cn/encodingerr.jpg