Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-2255

The Chinese Encoding Problem

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Incomplete
    • 1.2.4
    • None
    • Unknown
    • None
    • Operating System: Windows XP
      Platform: PC
    • 31817

    Description

      My platform encoding is gb2312,so when i put chinese words in the resources
      file and retrive them in the jsp page,i got the incorrect word.

      So I write a new messageresourcefactory and messageresource class which
      extends the PropertyMessageResourcesFactory and PropertyMessageResources class
      and override the getMessage() method in my new messageresource class like this:
      public String getMessage(Locale locale, String key) {
      String srcmessage = super.getMessage(locale,key);
      String destmessage = null;
      try

      { byte[] bytes = srcmessage.getBytes("ISO-8859-1"); destmessage = new String(bytes); }

      catch(Exception e)

      { System.out.println("Exception From nickmessageresources"); }


      return destmessage;
      }
      then in the struts-config.xml file i use my new
      PropertyMessageResourcesFactory class to load the message resource.And put the
      following code "<%@page contentType="text/html;chatset=gb2312"%>" at the
      beginnig of each jsp fiel,then i get the chinese word in the resource file
      correctly.
      I think this encoding problem maybe exist in each non-english country.
      I hope in the new version of struts,the default PropertyMessageResources's
      getMessage() method should first use the getBytes() method with the ISO-8859-1
      charset then use the locale to reconstruct the desire String.

      Attachments

        Activity

          People

            Unassigned Unassigned
            letaliang@msn.com nickcen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: