You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by GitBox <gi...@apache.org> on 2020/05/27 04:09:42 UTC

[GitHub] [tomcat] xiaofanTo opened a new pull request #291: fixed-chinese-encoding

xiaofanTo opened a new pull request #291:
URL: https://github.com/apache/tomcat/pull/291


   When I use Chinese, I find that the log printed by the console is garbled,like this :
   26-May-2020 09:42:32.374 严重 [main] org.apache.catalina.startup.Catalina.initDirs 在[catalina-home1/temp]找不到指定的临时文件夹
   26-May-2020 09:42:33.259 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/@VERSION@
   26-May-2020 09:42:33.259 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建:        @VERSION_BUILT@
   26-May-2020 09:42:33.259 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号(:     @VERSION_NUMBER@
   26-May-2020 09:42:33.260 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称:      Mac OS X
   
   So I changed the encoding so that there is no problem.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] xiaofanTo commented on pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
xiaofanTo commented on pull request #291:
URL: https://github.com/apache/tomcat/pull/291#issuecomment-633821731


   ok , all info in this .
   tomcat version : 8.5.55
   java version : 1.8.0_181-b13
   os version : Mac OS X 10.15.4
   
   and i  debug this problem this morning .
   I found the final cause of this problem is because of the **PropertyResourceBundle** class .
   
   My test code is as follows :
   `
   public class Test {
       public static void main(String[] args) throws IOException {
           //1. inputstream
           InputStream inputStream = Test.class.getResourceAsStream("/test.properties");
           PropertyResourceBundle prb1 = new PropertyResourceBundle(inputStream);
           String title1 = prb1.getString("title");
           System.out.println(title1);
   
           //2. reader
           InputStreamReader reader = new InputStreamReader(Test.class.getResourceAsStream("/test.properties"),"UTF-8");
           PropertyResourceBundle prb2 = new PropertyResourceBundle(reader);
           String title2 = prb2.getString("title");
           System.out.println(title2);
       }
   }
   `
   the test.properties contens is : 
   `title=测试`
   
   When you initialize him, the input is an InputStream , then Properties will load this stream,The garbled problem arises here . 
   ` public PropertyResourceBundle (InputStream stream) throws IOException {
           Properties properties = new Properties();
           properties.load(stream);
           lookup = new HashMap(properties);
       }
   `
   
   So I think you should replace the above with the following initialization method. 
   ` public PropertyResourceBundle (Reader reader) throws IOException {
           Properties properties = new Properties();
           properties.load(reader);
           lookup = new HashMap(properties);
       }`
   
   when you use this reader , you can set the charset to **utf-8** 
   
    


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] xiaofanTo edited a comment on pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
xiaofanTo edited a comment on pull request #291:
URL: https://github.com/apache/tomcat/pull/291#issuecomment-633821731






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] gmshake edited a comment on pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
gmshake edited a comment on pull request #291:
URL: https://github.com/apache/tomcat/pull/291#issuecomment-633830923


   @xiaofanTo 
   
   Refer to the javadoc of `java.util.Properties`,  https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html, 
   
   > The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.
   
   What you experienced is expected behavior :)
   
   Following the javadoc, try converting the property file `test.properties` with `native2ascii` tool,
   ```bash
   native2ascii test.properties > test.properties
   ```
   you'll get correct console output :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] gmshake commented on pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
gmshake commented on pull request #291:
URL: https://github.com/apache/tomcat/pull/291#issuecomment-633788316






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] markt-asf commented on pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
markt-asf commented on pull request #291:
URL: https://github.com/apache/tomcat/pull/291#issuecomment-634493356


   I'm guessing you are running Tomcat directly from source in an IDE. As @gmshake pointed out, you'll need to convert the property files to ASCII to do that (the Tomcat build process does this). There are various other approaches you can use depending on exactly what you are trying to achieve. The users mailing list is the place to seek help with this.
   http://tomcat.apache.org/


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[GitHub] [tomcat] markt-asf closed pull request #291: fixed-chinese-encoding

Posted by GitBox <gi...@apache.org>.
markt-asf closed pull request #291:
URL: https://github.com/apache/tomcat/pull/291


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org